Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

CNContact.Value

Queries the value of contact.

Component Version macOS Windows Linux Server iOS SDK
Contacts 8.4 ✅ Yes ❌ No ❌ No ❌ No ✅ Yes
MBS( "CNContact.Value"; ContactIdentifier; Selector { ; ImageType; FileName } )   More

Parameters

Parameter Description Example Flags
ContactIdentifier The contact identifier. "46B1E34D-58F9-4B6B-A80D-0F71ABB87A0E"
Selector Which value to return. "nickname"
ImageType The type of image to return.
Either JPEG, PNG, GIF or BMP. Default is JPEG.
"JPEG" Optional
FileName The filename to use for the picture.
Default is "image" with the extension matching the image type.
"test.jpg" Optional

Result

Returns value or error.

Description

Queries the value of contact.
Selector can be birthday, contactRelations, dates, departmentName, emailAddresses, familyName, givenName, imageData, imageDataAvailable, instantMessageAddresses, jobTitle, middleName, namePrefix, nameSuffix, nickname, nonGregorianBirthday, organizationName, phoneNumbers, phoneticFamilyName, phoneticGivenName, phoneticMiddleName, phoneticOrganizationName, postalAddresses, previousFamilyName, socialProfiles, thumbnailImageData, note, type or urlAddresses.
ImageData and thumbnailImageData are returned as container and you can pass in ImageType and FileName to use.
PhoneNumbers, emailAddresses, postalAddresses, urlAddresses, contactRelations, socialProfiles, instantMessageAddresses, dates, birthday and nonGregorianBirthday are returned as JSON.

See also Apple's documentation:
https://developer.apple.com/documentation/contacts/cncontact

Examples

Get my phone numbers:

MBS("CNContact.Value"; MBS("CNContactStore.UnifiedMeContact"); "phonenumbers")

Example result:
[ { "identifier" : "7AA474C5-CB5B-406F-9C19-077E14E8F48B", "label" : "_$!<Mobile>!$_", "value" : "+49 1234 56789" }, { "identifier" : "96F71635-B932-49C5-ABA6-905528A152D0", "label" : "_$!<Work>!$_", "value" : "+49 1234 56789" } ]

Get my social profiles:

MBS("CNContact.Value"; MBS("CNContactStore.UnifiedMeContact"); "socialprofiles")

Example result:
[ { "identifier" : "DC992125-7999-4C52-ADF6-D544BC3ADA04", "label" : "Twitter", "value" : { "username" : "MBSPlugins", "userIdentifier" : null, "service" : "Twitter", "urlString" : "http:\/\/twitter.com\/MBSPlugins" } }, { "identifier" : "4D26EDF7-EE68-4125-AAF1-C79C5D4A66AA", "label" : "Facebook", "value" : { "username" : "MonkeybreadSoftware", "userIdentifier" : null, "service" : "Facebook", "urlString" : "http:\/\/facebook.com\/MonkeybreadSoftware" } } ]

Get image of contact as container value:

MBS( "CNContact.Value"; $contact; "imageData")

Query email addresses:

MBS( "CNContact.Value"; "BD2307E5-92F6-4A8F-946D-C4804615C18B:ABPerson"; "emailAddresses")

Get type of contact:

MBS( "CNContact.Value"; $contact; "type")

Example result: Returns "Organization" or "Person"

Query contacts app for Note for a contact:

# Read Contact Note via AppleScript
Set Variable [ $theID ; Value: "773E1A42-ABCD-4CCF-88DE-E9C64BEE6D33:ABPerson" ]
# Compile AppleScript
Set Variable [ $ScriptID ; Value: MBS( "AppleScript.Compile"; "property theID : \"\"¶ tell application \"Contacts\"¶ set theContact to the first person whose id is theID¶ return note of theContact¶ end tell" ) ]
# run a query or multiple
Set Variable [ $r ; Value: MBS( "AppleScript.SetPropertyValue"; $ScriptID; "theID"; $theID ) ]
Set Variable [ $result ; Value: MBS( "AppleScript.Execute"; $ScriptID) ]
Show Custom Dialog [ "Result from AppleScript" ; $result ]
# free memory
Set Variable [ $r ; Value: MBS( "AppleScript.Close"; $ScriptID) ]

See also

Blog Entries

This function checks for a license.

Created 1st August 2018, last changed 17th November 2023


CNContact.UnifiedContacts - CNContactPicker.Close