Wednesday, August 27, 2014

#1 2012-01-27 01:01:28 am

hypehuman
Member
Registered: 2012-01-25
Posts: 2

Applescript and Address Book

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?

Model: MacBook Pro core 2 duo
Browser: Safari 534.52.7
Operating System: Mac OS X (10.7)

Offline

 

#2 2012-01-27 02:35:55 am

StefanK
Member
From: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 10488
Website

Re: Applescript and Address Book

Hi,

since 10.6 you have to save the address book explicitly in the script.
Just add a save line at the end

Applescript:



       end repeat
   end repeat
   save
end tell


regards

Stefan

Offline

 

#3 2012-01-30 09:56:38 pm

hypehuman
Member
Registered: 2012-01-25
Posts: 2

Re: Applescript and Address Book

Thanks, that worked perfectly!

Offline

 

#4 2012-03-27 08:08:06 am

colonelsnow
Member
Registered: 2012-03-27
Posts: 2

Re: Applescript and Address Book

How would this script need to be modified to make the change for everyone in the address book rather than inserting one contact name at a time, i.e. "Andy"

Offline

 

#5 2012-03-27 08:10:55 am

StefanK
Member
From: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 10488
Website

Re: Applescript and Address Book

colonelsnow wrote:

How would this script need to be modified to make the change for everyone in the address book rather than inserting one contact name at a time, i.e. "Andy"

omit "whose first name = "Andy""


regards

Stefan

Offline

 

#6 2012-03-27 09:48:34 am

colonelsnow
Member
Registered: 2012-03-27
Posts: 2

Re: Applescript and Address Book

That did it.

One last question. How do you make it make all the changes without prompting you to accept each one that it finds?

Offline

 

#7 2012-03-27 09:57:15 am

StefanK
Member
From: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 10488
Website

Re: Applescript and Address Book

delete or comment out the display dialog line


regards

Stefan

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.027 seconds, 8 queries executed ]

RSS (new topics) RSS (active topics)