This is an enhancement to this previous hint, which only syncs contacts with phone numbers to the iPhone (because Smart Address Book groups are not synchronized to the iPhone).
Because people forget to call that script every time they add a new contact with a phone number, this process must be automated. This hint creates a tool that monitors the Address Book file, and calls a command line app every time it changes. This hint was tested on 10.5 and 10.6.
ABGroupUpdater
The AppleScript solution takes too long and opens the Address Book which can be irritating. This small Objective-C app (download: binary [8KB] • source [6KB]) is fast and configurable.
(To compile this app yourself, with Xcode installed, do this in Terminal after downloading and expanding the source file: gcc ABGroupUpdater.m -o ABGroupUpdater -framework Foundation -framework AddressBook.)
The calling syntax is:
./ABGroupUpdater -property Phone -group Phones -vWhere -property Phone means that all contacts with a phone number are added to the group Phones. WARNING: If this group already exists in your Address Book, it will be modifed. The -v argument is verbose mode, which can be removed in the final call.
ABGroupUpdater -property Email -group Emails -vTo trigger ABGroupUpdater, we install a LaunchAgent. Save the following to a file named com.macosxhints.addressbookGroupUpdater.plist in the ~/Library/LaunchAgents folder (create it if necessary):
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>com.macosxhints.addressbookgroupupdater</string> <key>ProgramArguments</key> <array> <string>/Users/USER/Library/Application Support/ABGroupUpdater/ABGroupUpdater</string> <string>-property</string> <string>Phone</string> <string>-group</string> <string>Phones</string> <string>-v</string> </array> <key>RunAtLoad</key> <false/> <key>ThrottleInterval</key> <integer>60</integer> <key>WatchPaths</key> <array> <string>/Users/USER/Library/Application Support/AddressBook/AddressBook-v22.abcddb</string> </array> </dict> </plist>
Mac OS X Hints
http://hints.macworld.com/article.php?story=2010032201472983