I bought an iPod touch and in Contacts it doesn’t display nickname (just “no name”) so I need to split all nicknames in Mac OS X’s Address Book into first and last name. Rather than do this manually for a few hundred names - what fun! - I was wondering if it’s possible to run an applescript that would count the number of words in the nickname field, say Paul Michael Smith, or John Adams, copy the last word into the Last Name field and copy the first word into the First Name field. Would anyone happen to know if this possible?
I made up a small group of 10 people entitled Test, and this script worked just fine:
tell application "Address Book"
set all_Persons to every person in group "Test"
repeat with per_son in all_Persons
set nknm to per_son's nickname
set per_son's first name to word 1 of nknm
set per_son's last name to word -1 of nknm
end repeat
end tell
tell application "Address Book"
set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, space}
repeat with onePerson in (get people whose nickname is not missing value)
set N to text items of (get nickname of onePerson)
tell contents of onePerson
set first name to text items 1 thru -2 of N as text
set last name to text item -1 of N as text
end tell
end repeat
set AppleScript's text item delimiters to ASTID
end tell
Not a single No Name in the touch contact list now - great, thanks!
In the end I created a smart list and set a couple rules - no first name and no company - then ran Craig’s script on the smart list. Your script gave me an error Stefan when I tried to run it because some of the text strings in the nickname field weren’t just names - there were things like email addresses, strangely! So I just dragged cards I wanted to change into the smart list and ran the script… I still had to do some manual changes, but overall it speeded things up no end - thanks again!