Apple script, insert email of group in mail

Discussion in 'Mac Programming' started by eric98, Nov 5, 2012.

  1. macrumors newbie

    Joined:
    Nov 5, 2012
    #1
    Hi,

    I tried to get the email adress of any persons of a group (in adress book) in a new outgoing message.

    Did some one have any idea how the apple script should look like?

    many thank's for your help
     
  2. macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #2
    An example of a Work group with 2 persons in it. Both of them with a work and home email address.

    Code:
    set emailList to {}
    tell application "Address Book"
    	set thePersons to get every person of group "Work"
    	repeat with aPerson in thePersons
    		set end of emailList to the value of aPerson's email
    	end repeat
    end tell
    
    tell application "Mail"
    	set theMessage to make new outgoing message with properties {visible:true, sender:"me.somewhere@rainbow.com", subject:"Testing", content:"Just testing Mail with Address Book"}
    	tell theMessage
    		repeat with anItem in emailList
    			repeat with anAddressItem in anItem
    				make new to recipient at end of to recipients with properties {address:anAddressItem}
    			end repeat
    		end repeat
    	end tell
    end tell
    
     

    Attached Files:

Share This Page