I would like to ask if there is a quick method that I can use in order to change all the contacts names in my address book to appear in capitals at once. I am asking this because I have almost 300 contacts and it will take me many hours to do it one by one.
Thanks in advance.
Chris.
Model: iMac 3.06 GHz, Intel Core 2 Duo
Browser: Safari 533.17.8
Operating System: Mac OS X (10.6)
tell application "Address Book"
script a
property l : get people
end script
repeat with aPerson in a's l
set {first name:fName, last name:lName} to aPerson
if fName is not missing value and (ASCII number (first character of fName)) > 96 then set first name of contents of aPerson to my capitalize(fName)
if lName is not missing value and (ASCII number (first character of lName)) > 96 then set last name of contents of aPerson to my capitalize(lName)
end repeat
end tell
on capitalize(n)
say "here"
do shell script "echo " & quoted form of n & " | awk '{for(i=1;i<=NF;i++)sub(/./,toupper(substr($i,1,1)),$i)}1'"
end capitalize
Hello Stefan and thank you very much for your reply.
I did run this script with my Apple Script Editor but when it finished nothing in my Address book had changed. None of my contacts names was in capital letters.
Sorry, I overlooked that you’re running Snow Leopard. It requires to save the address book explicitly
Just add the save command at the end of the application tell block
I did motify the script you send me but after running it i get a missing value error in the event log.
I dodnt know many things about scripts and code so i beleive that i am not doing something correctly.
Can you please send me the complete script corrected.
tell application "Address Book"
script a
property l : get people
end script
repeat with aPerson in a's l
set {first name:fName, last name:lName} to aPerson
if fName is not missing value and (ASCII number (first character of fName)) > 96 then set first name of contents of aPerson to my capitalize(fName)
if lName is not missing value and (ASCII number (first character of lName)) > 96 then set last name of contents of aPerson to my capitalize(lName)
end repeat
save addressbook
end tell
on capitalize(n)
say "here"
do shell script "echo " & quoted form of n & " | awk '{for(i=1;i<=NF;i++)sub(/./,toupper(substr($i,1,1)),$i)}1'"
end capitalize
Ok i did remove the say line and then hit compile.
It runs but after a while it stops giving me this missing value error.
This is what i Compile and Run.
tell application “Address Book”
script a
property l : get people
end script
repeat with aPerson in a's l
set {first name:fName, last name:lName} to aPerson
if fName is not missing value and (ASCII number (first character of fName)) > 96 then set first name of contents of aPerson to my capitalize(fName)
if lName is not missing value and (ASCII number (first character of lName)) > 96 then set last name of contents of aPerson to my capitalize(lName)
end repeat
save addressbook
end tell
on capitalize(n)
do shell script “echo " & quoted form of n & " | awk ‘{for(i=1;i<=NF;i++)sub(/./,toupper(substr($i,1,1)),$i)}1’”
end capitalize
The first image is no error message, the displayed missing value is just the result of the last executed line.
In the second image the error message says that the on capitalize() handler is missing.