<div class="meta" robots="noindex">

</div>

Class

# AddressBook

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<div class="warning">

<div class="title">

Warning

</div>

This item was deprecated in version 2019r2. There is no replacement.

</div>

## Description

Provides the ability to read from and write to the macOS Address Book.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                                               | Type                                                     | Read-Only | Shared |
|----------------------------------------------------|----------------------------------------------------------|-----------|--------|
| `CurrentUser<addressbook.currentuser>`             | `AddressBookContact</api/deprecated/addressbookcontact>` |           |        |
| `HasUnsavedChanges<addressbook.hasunsavedchanges>` | `Boolean</api/data_types/boolean>`                       |           |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                             | Parameters                                                       | Returns                                                    | Shared |
|----------------------------------|------------------------------------------------------------------|------------------------------------------------------------|--------|
| `Add<addressbook.add>`           | Record As `AddressBookRecord</api/deprecated/addressbookrecord>` |                                                            |        |
| `Contacts<addressbook.contacts>` |                                                                  | `AddressBookContact()</api/deprecated/addressbookcontact>` |        |
| `Find<addressbook.find>`         | Query As `String</api/data_types/string>`                        | `AddressBookRecord()</api/deprecated/addressbookrecord>`   |        |
| `Groups<addressbook.groups>`     |                                                                  | `AddressBookGroup()</api/deprecated/addressbookgroup>`     |        |
| `Remove<addressbook.remove>`     | Record As `AddressBookRecord</api/deprecated/addressbookrecord>` |                                                            |        |
| `Save<addressbook.save>`         |                                                                  | `Boolean</api/data_types/boolean>`                         |        |

## Property descriptions

<div id="addressbook.currentuser">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AddressBook.CurrentUser

**CurrentUser** As `AddressBookContact</api/deprecated/addressbookcontact>`

Gets the current user's "me" entry.

This code accesses the current user's first name.

``` xojo
Dim book As New AddressBook
book = System.AddressBook
MsgBox(book.CurrentUser.FirstName.Value)
```

<div id="addressbook.hasunsavedchanges">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AddressBook.HasUnsavedChanges

**HasUnsavedChanges** As `Boolean</api/data_types/boolean>`

If `True</api/language/true>`, a Save is needed. Call the Save method to save the changes.

``` xojo
Dim book As New AddressBook
book = System.AddressBook

If book.HasUnsavedChanges Then
  If book.Save Then
    MsgBox("The changes were successful!")
  End If
Else
  MsgBox("There were no unsaved changes!")
End If
```

## Method descriptions

<div id="addressbook.add">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AddressBook.Add

**Add**(Record As `AddressBookRecord</api/deprecated/addressbookrecord>`)

Adds the record to the Address Book.

The following code adds a new contact to the address book.

``` xojo
Dim book As New AddressBook
Dim myContact As AddressBookContact
book = System.AddressBook
myContact = New AddressBookContact

myContact.FirstName = "Xena"
myContact.LastName = "Smith"
myContact.CompanyName = "Xanadu"
myContact.JobTitle = "Free Lance"

book.Add(myContact)

If book.HasUnsavedChanges Then
  If book.Save Then
    MsgBox("The AddressBook was saved!")
  End If
Else
  MsgBox("There were no unsaved changes!")
End If
```

<div id="addressbook.contacts">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AddressBook.Contacts

**Contacts** As `AddressBookContact()</api/deprecated/addressbookcontact>`

Returns an array of all the contacts in the Address Book as an `AddressBookContact</api/deprecated/addressbookcontact>`.

<div id="addressbook.find">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AddressBook.Find

**Find**(Query As `String</api/data_types/string>`) As `AddressBookRecord()</api/deprecated/addressbookrecord>`

Find performs a textual search on all Contacts fields for the string passed. It returns an array of all matching Contacts records.

<div id="addressbook.groups">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AddressBook.Groups

**Groups** As `AddressBookGroup()</api/deprecated/addressbookgroup>`

Returns an array of all the groups as an `AddressBookGroup</api/deprecated/addressbookgroup>`.

<div id="addressbook.remove">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AddressBook.Remove

**Remove**(Record As `AddressBookRecord</api/deprecated/addressbookrecord>`)

Removes the record from the Address Book.

<div id="addressbook.save">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AddressBook.Save

**Save** As `Boolean</api/data_types/boolean>`

Saves changes to the Address Book. Returns a `Boolean</api/data_types/boolean>`, `True</api/language/true>` if the save is successful.

## Sample code

You can create an instance of this class in either of two ways. Use the `New</api/language/new>` operator in the usual way or call the <span class="title-ref">AddressBook</span> property of the `System</api/os/system>` module.

``` xojo
Var book As New AddressBook
' or
Var book As AddressBook
book = System.AddressBook
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

You can obtain the contacts using the Contacts method. This code populates an the array of contacts from the user's Address Book.

``` xojo
Var book As AddressBook
book = System.AddressBook

Var contacts() As AddressBookContact
contacts = book.Contacts
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Once you have the array of contacts, you can get its size with the `Arrays.LastIndex<arrays.lastindex>` function and use the properties of the `AddressBookContact</api/deprecated/addressbookcontact>` class to extract any field. The `AddressBookData</api/deprecated/addressbookdata>` class is able to convert to a `String</api/data_types/string>` automatically in most cases. If the field does not contain multiple values, it will return the string.

For example, you can loop through the array of `AddressBookContacts</api/deprecated/addressbookcontact>` and get the company names. This code puts the company names in a `ListBox</api/deprecated/listbox>`.

``` xojo
Var book As AddressBook
book = System.AddressBook

For Each Contact As AddressBookContact In book.Contacts
  Listbox1.AddRow(Contact.CompanyName)
Next
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

You can get the current user's "me" entry from this and extract a field:

``` xojo
Var book As AddressBook
book = System.AddressBook
MsgBox(book.CurrentUser.FirstName)
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Here is another way to get a property. It uses the Value method of the `AddressBookData</api/deprecated/addressbookdata>` method.

``` xojo
Var book As AddressBook
book = System.AddressBook
MsgBox(book.CurrentUser.FirstName.Value)
```

## Compatibility

All project types on all supported operating systems.

## See also

`Object</api/data_types/additional_types/object>` parent class; `AddressBookAddress</api/deprecated/addressbookaddress>`, `AddressBookContact</api/deprecated/addressbookcontact>`, `AddressBookData</api/deprecated/addressbookdata>`, `AddressBookGroup</api/deprecated/addressbookgroup>`, `AddressBookRecord</api/deprecated/addressbookrecord>` classes.
