Occasionally you'll find that you've created a contact using Add to Address Book in a message where the sender was using an e-mail client that puts the last name before the first name, like so: last name, first name. Perhaps you even imported hundreds of contacts of this type from some other application. Microsoft Entourage does not understand this format and puts the last name and the comma into the First Name field, and vice versa, and then sorts by the (real) first name, placed last. A simple script can put that right.
tell application "Microsoft Entourage"
set backToFronts to every contact whose ¬
first name ends with ","
repeat with theContact in backToFronts
tell theContact
set {realFirst, realLast} to {last name, first name}
try
set realLast to text 1 thru -2 of realLast
on error
set realLast to ""
end try
set {first name, last name} to {realFirst, realLast}
end tell
end repeat
display dialog "All done!"
end tellNote that you use the
whose
filter in the first line to get only the contacts with commas; otherwise, you'd end up switching names of contacts that were correct to begin with. You use the
tell theContact
block rather than using
of theContact
primarily to be able to set a list of properties in one line, as follows:
set theContact's {first name, last name} to {realFirst, realLast}If you direct this code to
theContact
from outside of a
tell
block, it errors. However, getting a list of properties in one line always works, as follows:
set {realFirst, realLast} to theContact's {last name, first name}

