Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Swap Address Book first/last names via AppleScript Apps
When I copy email addresses from Mail to Address Book, the order of names is frequently mangled, placing the last name in the first name space, and vice versa. As far as I understand, the Swap First/Last menu item only changes the display order, not the stored location of the data. (Ephramz previously posted a similar solution to a more difficult problem.)

This short applescript just trades the first and last names for the selected entries.
tell application "Address Book"
  set mySelected to selection
  repeat with myPerp in mySelected
    set tmp to last name of myPerp
    set last name in myPerp to (first name in myPerp)
    set first name in myPerp to tmp
  end repeat
end tell
I saved this in my Library » Scripts » Address Book Scripts. Ideally, I'd bind a hot key to it run it every time I come across a swapped name, but for now I just run it from the menu.
    •    
  • Currently 2.75 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (4 votes cast)
 
[11,735 views]  

Swap Address Book first/last names via AppleScript | 4 comments | Create New Account
Click here to return to the 'Swap Address Book first/last names via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Works nice, thanks! (n/t)
Authored by: rusto on Apr 05, '07 09:44:59AM

n/t



[ Reply to This | # ]
Swap Address Book first/last names via AppleScript
Authored by: Marc Wolfgram on Apr 08, '07 11:08:58AM

Cool, simple and works. I saved this as a script: ~/Library/Scripts/Address Book/Swap Name Fields.scpt so it can be involked from the menubar script icon. I've got a couple of clients with imported Outlook (lookout?) address csv files that came in backassward and this is a fast and clean fix. Thanks!
-- Marc



[ Reply to This | # ]
Swap Address Book first/last names via AppleScript
Authored by: vorm on Mar 28, '08 10:00:25AM

How would i swap the last name with organization name?
In fact I don't have names, only organization names, but the vCards i got put those names in the last name field.

--

so far i have this, but it does not work for me:

tell application "Address Book"
set last name to organization
end tell



[ Reply to This | # ]
Swap Address Book first/last names via AppleScript
Authored by: dethbunny on Mar 12, '10 05:16:35PM

I had to add a "save" statement after the repeat loop to make everything work on Snow Leopard.



[ Reply to This | # ]