PDA

View Full Version : simple applescript email question




SouthernAtHeart
Feb 2, 2012, 09:49 AM
I'm trying to move any person in a specified group to the group "test2" if they have an email address, but can't quite get it...
repeat with theContact in people in the group named theirGroup
if (the email of theContact is not missing) then
add theContact to group "test2"
save
end if
end repeat
I must be close?



Mark FX
Feb 3, 2012, 02:15 PM
I assume your scripting the Mail app ?

Also you need to post more of the Applescript's code, in order for someone
to help you with the code.

But I think your line.


(the email of theContact is not missing)


Should probably be.


(the email of theContact is not missing value)


But I am only guessing with out the rest of the script's code.

Regards Mark

SouthernAtHeart
Feb 3, 2012, 04:13 PM
tell application "Address Book"
repeat with theContact in people in the group named "test1"
repeat with emailID in emails of theContact
add theContact to the group "test2"
end repeat
end repeat
end tell

I am trying to figure out how to add contacts in one group that have an email address into another group.
This code doesn't work yet. I've tried numerous things. :(
Thanks for the help.

Red Menace
Feb 3, 2012, 06:31 PM
When you get the email [addresses] of a person, the result is a list of those emails. Even if there are no emails, the result will still be a list (although an empty one), so your script would be something like:

tell application "Address Book"
repeat with theContact in (people in group "test1")
if (email of theContact is not {}) then
add theContact to group "test2"
save
end if
end repeat
end tell

Also be careful about using class or property names as commands. If you are wanting to use a filter reference form (https://developer.apple.com/library/mac/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_reference_forms.html#//apple_ref/doc/uid/TP40000983-CH4g-BAJJHEFE), you can use something like (groups whose name is "test") - note that this will also be a list.

SouthernAtHeart
Feb 3, 2012, 07:13 PM
Thanks also for that other tip.