simple applescript email question

Discussion in 'Mac Programming' started by SouthernAtHeart, Feb 2, 2012.

  1. macrumors newbie

    Joined:
    Nov 6, 2011
    #1
    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...
    Code:
    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?
     
  2. macrumors member

    Mark FX

    Joined:
    Nov 18, 2011
    #2
    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.

    Code:
    (the email of theContact is not missing)
    
    Should probably be.

    Code:
    (the email of theContact is not missing value)
    
    But I am only guessing with out the rest of the script's code.

    Regards Mark
     
  3. thread starter macrumors newbie

    Joined:
    Nov 6, 2011
    #3
    Code to find contacts with email

    Code:
    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.
     
  4. macrumors 6502

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #4
    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:

    Code:
    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, you can use something like (groups whose name is "test") - note that this will also be a list.
     
  5. thread starter macrumors newbie

    Joined:
    Nov 6, 2011
    #5
    Thanks

    Thanks also for that other tip.
     

Share This Page