groups

Link to this snippet:


Download to Code Collector

language: AppleScript
licence: Other

Split First Name - Address Book

options: send to code collectorview all seydoggy's snippets
(*
Split First Name

By Adam Merrifield <http://seydoggy.com>

This script will cause irreversible changes
to contacts in your Address Book.

USE AT YOUR OWN RISK!!

This script will search for contacts whose first names contain a spaces and whose last name is not present. Going on the assumption that the first and last name are both contained in the first name (hence the space), the script takes the first word and the last word and uses them for a proper first and last name.

- r1 12-23-09 14:23
*)
tell application "Address Book"
	(*
	set first name to first word in first name
	set last name to last word in first name
	*)
	set the thePeople to (every person whose (last name is missing value and first name contains " "))
	repeat with i from 1 to count of thePeople
		set theirName to (first name of (item i of thePeople))
		set firstName to (first word of theirName)
		set lastName to (last word of theirName)
		set properties of (item i of thePeople) to {first name:firstName, last name:lastName}
		save
	end repeat
end tell