Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ViViDboarder

macrumors 68040
Original poster
Jun 25, 2008
3,447
2
USA
So I'm having some weird issues with deleting items from my address book using Applescripts...

I run a delete script and nothing seems to happen, so I did a little test. First I ran:
Code:
tell application "Address Book"
	count (emails of people whose label is "mobile")
end tell
And it tells me '221'

Then I run:
Code:
tell application "Address Book"
	delete (emails of people whose label is "mobile")
end tell
And it gives no errors.

Finally I run the first script over again and it gives me 0.

I'd think that all would be well, but I open address book and it seems like the items are still there. In fact, I know they are still there. I can close Address Book and then open it again and run the count script and it gives me 221 again!

Any idea how to get these changes to stick?
 
You say no errors, but are you expecting AS to burp if there's a mistake?

You might want to wrap your delete line in a try block just to be sure.

Code:
tell application "Address Book"
	try
		delete (emails of people whose label is "mobile")
	on error errMsg number errNum
		display dialog "Error No. " errNum & return & errMsg
	end try
end tell

mt
 
You say no errors, but are you expecting AS to burp if there's a mistake?

You might want to wrap your delete line in a try block just to be sure.

Code:
tell application "Address Book"
	try
		delete (emails of people whose label is "mobile")
	on error errMsg number errNum
		display dialog "Error No. " errNum & return & errMsg
	end try
end tell

mt

Yea, nothing comes up. I'm almost certain it thinks it's doing something. I played around and had it show all labels for the selected person. It showed:
home
mobile
mobile

Then I ran my delete and ran the show script again and it shows:
home

And that's it. But when I look at the entry all the items are there and if I restart Address Book they are still there and the Applescript will show that again.
 
Try this:

Code:
tell application "Address Book"
	try
		delete (emails of people whose label is "mobile")
	on error errMsg number errNum
		display dialog "Error No. " errNum & return & errMsg
	end try
	[B]save[/B]
end tell

mt
 
It says missing value. I'll try a slightly different script to save thePerson later.

Worked.

I used the script attached and added the line for the save this_person.

Thanks! I had looked all over and all the scripts I found were doing exactly what I had before. I wonder if 10.6 behaves differently and these scripts are for 10.5. Oh well.

I edited these lines and added the save:
Code:
repeat with email_id in emails_to_remove
	delete (emails of this_person whose id is email_id)
	set emails_removed to emails_removed + 1
end repeat
save this_person
 

Attachments

  • Remove Emails for Label.zip
    3.3 KB · Views: 111
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.