Class
AddressBook
Warning
This item was deprecated in version 2019r2. There is no replacement.
Description
Provides the ability to read from and write to the macOS Address Book.
Properties
Name |
Type |
Read-Only |
Shared |
---|---|---|---|
Methods
Name |
Parameters |
Returns |
Shared |
---|---|---|---|
Record As AddressBookRecord |
|||
Query As String |
|||
Record As AddressBookRecord |
|||
Property descriptions
AddressBook.CurrentUser
CurrentUser As AddressBookContact
Gets the current user's "me" entry.
This code accesses the current user's first name.
Dim book As New AddressBook
book = System.AddressBook
MsgBox(book.CurrentUser.FirstName.Value)
AddressBook.HasUnsavedChanges
HasUnsavedChanges As Boolean
If True, a Save is needed. Call the Save method to save the changes.
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
AddressBook.Add
Add(Record As AddressBookRecord)
Adds the record to the Address Book.
The following code adds a new contact to the address book.
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
AddressBook.Contacts
Contacts As AddressBookContact()
Returns an array of all the contacts in the Address Book as an AddressBookContact.
AddressBook.Find
Find(Query As String) As AddressBookRecord()
Find performs a textual search on all Contacts fields for the string passed. It returns an array of all matching Contacts records.
AddressBook.Groups
Groups As AddressBookGroup()
Returns an array of all the groups as an AddressBookGroup.
AddressBook.Remove
Remove(Record As AddressBookRecord)
Removes the record from the Address Book.
AddressBook.Save
Save As Boolean
Saves changes to the Address Book. Returns a Boolean, True if the save is successful.
Sample code
You can create an instance of this class in either of two ways. Use the New operator in the usual way or call the AddressBook property of the System module.
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.
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 function and use the properties of the AddressBookContact class to extract any field. The AddressBookData class is able to convert to a 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 and get the company names. This code puts the company names in a ListBox.
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:
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 method.
Var book As AddressBook
book = System.AddressBook
MsgBox(book.CurrentUser.FirstName.Value)
Compatibility
All project types on all supported operating systems.
See also
Object parent class; AddressBookAddress, AddressBookContact, AddressBookData, AddressBookGroup, AddressBookRecord classes.