Applescript and Address Book

Joined
Jan 25, 2012
Messages
2
Reaction score
0
Points
1
Hello, I have a question about how to use AppleScript to make bulk modifications to my Address Book. I am trying to find all phone numbers that are labeled as the person's "main" phone number, and change it to "other". This is because my phone does not sync entries under "main".

After googling a bunch of sites, I came up with the following code:
Code:
tell application "Address Book"
	set thePeople to every person whose first name = "Andy"
	repeat with thePerson in thePeople
		set thePhones to phones of thePerson
		repeat with thePhone in thePhones
			set theLabel to (label of thePhone)
			set theLastName to last name of thePerson
			display dialog theLastName & " " & theLabel
			if theLabel = "main" then
				set (label of thePhone) to "other"
			end if
		end repeat
	end repeat
end tell
When I run the script, it gives me three dialogs: "Jackson work", "Hu main", and "Long main". I run it a second time, and it says: "Jackson work", "Hu other", "Long other". It looks like it's worked!

However, if I look at the entries in Address Book, they have not changed. Furthermore, if I quit and reopen Address Book and run the script again, it goes back to saying "main" the first time and then "other" all subsequent times.

Anyone know what's up?
 
Joined
Aug 13, 2011
Messages
200
Reaction score
7
Points
18
Location
West Sussex
The code you have in the above script, does not change anything in the Address Book, but simply displays Dialog Boxes with the results.

You will have to change the script to change the settings in the Address Book app itself.

Although I do a lot of scripting, I have not scripted tje Address Book before, but you can
get a lot of expert help with Applescript at this Forum site.

MacScripter

Regards Mark
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top