New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

Start a Discussion

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

Applescript and Address Book

Post Reply New Thread Subscribe

Thread Tools

Member Since: Jan 25, 2012
Posts: 2
hypehuman is on a distinguished road

hypehuman is offline
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:
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?
QUOTE Thanks
Mark FX

Mark FX's Avatar
Member Since: Aug 13, 2011
Location: West Sussex, UK
Posts: 180
Mark FX has a spectacular aura about

Mark FX is offline
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.


Regards Mark
QUOTE Thanks

Member Since: Jan 25, 2012
Posts: 2
hypehuman is on a distinguished road

hypehuman is offline
Thanks for the tip! I posted my question on MacScripter and someone gave me the solution! Here's a link to the post: MacScripter / Applescript and Address Book
QUOTE Thanks

Post Reply New Thread Subscribe

« AppleScript - Tell iTunes to use specific AppleTV | Changing Mac Character Code (Glyphs) »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Starter
Last Post
How to find IP Address chidambaram OS X - Apps and Games 0 05-03-2011 01:20 AM
Applescript guru? help debug my script? Turk182 OS X - Development and Darwin 5 02-09-2009 11:29 AM
Automator or Applescript? Guru Meditation OS X - Operating System 1 11-22-2008 10:01 AM
Bluetooth + Address Book REMFan7 OS X - Operating System 0 12-31-2003 03:40 PM

All times are GMT -4. The time now is 01:43 AM.

Powered by vBulletin
Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.

Welcome to

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!

(4 digit year)

Already a member?