DasGenie: !Scrap
« Joel on IT Conversations | Main | PHP ROT(FL)-13 »

Montag, 4. Oktober 2004

Address Book - Switch first and last name Applescript

Today I will migrate my father from an old pc to an 20'' iMac G5, yeah. First thing was to get his addresses from Outlook into Address Book. After having found no decent export format in Outlook, I downloaded Thunderbird which imported the addresses nicely and could write an LDIF export which Address Book can import. So far so good. Sadly my father did fill in the Outlook name Form "Last Name - First Name" which as far as I have seen the UI is a likely error. To correct this I wrote a small Applescript that switches first and last name of the current selection:

-- place in "/Library/Scripts/Address Book Scripts/"

tell application "Address Book"
    
set mylist to selection
    
repeat with this_person in mylist
        
set first_name to first name of this_person
        
set last_name to last name of this_person
        
set first name of this_person to last_name
        
set last name of this_person to first_name
    
end repeat
end tell

Have Fun! And be aware that the Address Book updates the UI a little bit lazily...

14:10 - Montag, 4. Oktober 2004
Comments

Thank you!
Looking at your script finally helped me get a script right that would change all labels of the email addresses. When I synced my address book to my phone, anything that was labelled "other" would not be included in the address book in the phone. Changing 1025 contacts manually wasn't too tempting...

Posted by: Henrik at 31.10.04 17:59

This is great, having previously exposed my phone to a PC symcing attempt alot of the contacts names got swapped.This sorts them out!

One other problem I'm having is a comma now hanging on the end of the Surnames that I swapped...example:
was filed: Armstrong, Dan
now filed: Dan Armstrong,

Unfortaunately my scripting knowledge is almost zero, I have tried to tweak your script using a *trim_line* command but got nowhere. Is it possible to have a script that trims the comma (or last character) off the end of the *last_name* field??

I promise I will learn applescript myself very soon!

Posted by: Dan Armstrong at 15.12.04 11:43