Address Book bug: add to a group in "On My Mac" rather than in iCloud?

There appears to be a bug when adding an entry (a person) to a group when that group resides in “On My Mac” rather than in iCloud, if “Default Account” is iCloud. However, I want to know if anyone knows the “proper way” around that?

If I do this in Lion:

tell application "Address Book"
	make new person at group "myGroup" with properties {first name:"aFirstName", last name:"aLastName"}

then, if “Default Account” is iCloud, it will only work ok if myGroup is in iCloud. If the group is in “On My Mac” instead, the script will erroneously create the entry in iCloud with no linking to any group. I assume that is a bug – it should have created the entry in “On My Mac” and linked it to the named group.

I can manually change the Default Account to “On My Mac” which makes it work correctly with groups “On My Mac”, but the dictionary does not specify any terms related to “Default Account”, or where a group is stored, so the thing is not scriptable.

FYI: the reason I have some groups in iCloud and some other groups On My Mac is pretty obvious: There are some groups I simply do not want to be seen on the iPhone, and this way of structuring the groups appears to be the only way to make this happen.


Hi heb

You can set the Address Book settings before you create the contact(s).

Here’s what I tried on my machine running Lion 10.7.3

set myGroup to "_TestGroup_"
set aFirstName to "_FirstName_"
set aLastName to "_LastName_"

tell application "System Events" to if (exists (first application process whose bundle identifier is "")) then tell application "Address Book" to quit
delay 1

do shell script "/usr/libexec/PlistBuddy -c 'Set ABBookWindowController-MainBookWindow-groupList:selectedGroupEntryIdentifier \"ABAccountBrowsingGroupEntry:(null)\"' ~/Library/Preferences/"
do shell script "/usr/libexec/PlistBuddy -c 'Set ABDefaultSourceID \"_local\"' ~/Library/Preferences/"

tell application "Address Book"
	if (exists group myGroup) is false then make new group with properties {name:myGroup}
	make new person at group myGroup with properties {first name:aFirstName, last name:aLastName}
end tell

If you want to change the default account back to iCloud change both _local and ABAccountBrowsingGroupEntry:(null) to your active iClouds SourceID which is the same as the folder name containing the iCloud db found in ~/Library/Application Support/AddressBook/Sources/. It must look something like this

do shell script "/usr/libexec/PlistBuddy -c 'Set ABBookWindowController-MainBookWindow-groupList:selectedGroupEntryIdentifier \"ABAccountBrowsingGroupEntry:2EB6DB17-1C01-3C82-8500-26AB2D2B224D\"' ~/Library/Preferences/"
do shell script "/usr/libexec/PlistBuddy -c 'Set ABDefaultSourceID \"2EB6DB17-1C01-3C82-8500-26AB2D2B224D\"' ~/Library/Preferences/"

Hope it helps
Yannis A

I wanted to do the same thing in El Capitan but when I run the above script I have an error:
error “Set: Entry, "ABBookWindowController-MainBookWindow-groupList:selectedGroupEntryIdentifier", Does Not Exist” number 1