Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save markbao/505929 to your computer and use it in GitHub Desktop.
Save markbao/505929 to your computer and use it in GitHub Desktop.
This will allow you to sync your Mac OS X Address Book with Pine. It'll take a few seconds if you have a few hundred contacts.
-- adapted from http://forums.macosxhints.com/showthread.php?t=17762 but it actually works here
tell application "Address Book"
set pineBook to ""
-- Count people as we loop over all of the people in each group
set i to 1
repeat with thePerson in every person
-- Check that there are e-mail entries for this person
if email of thePerson exists then
set theName to (name of thePerson) as string
-- Output every e-mail address entered for this person
set j to 1
repeat with theEmail in emails of thePerson
set theEmailAddress to (value of theEmail) as string
set pineBook to pineBook & (theName & tab & theName & tab & theEmailAddress) as string
set pineBook to pineBook & ("
") as string
set j to j + 1
end repeat
end if
set i to i + 1
end repeat
-- Output to file ~/.addressbook
set pineBookFile to (((path to home folder) as string) & ".addressbook")
try
set the openPineBookFile to open for access file pineBookFile with write permission
set eof of the openPineBookFile to 0
write pineBook to the openPineBookFile starting at eof
close access the openPineBookFile
return
on error
try
close access file pineBookFile
end try
-- Dump the result if there is a file error
return pineBook
end try
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment