Automator Variable in AppleScript

Discussion in 'Mac Programming' started by vloryan, Aug 22, 2014.

  1. vloryan, Aug 22, 2014
    Last edited: Aug 22, 2014

    vloryan macrumors member

    Joined:
    Jan 11, 2014
    #1
    Hi, how can i use an Automator variable like "email" in an Automator AppleScript window? I would like to use that "email" variable within Automator with "Run in AppleScript".

    Code:
    tell application "Mail"
     
    	set theSubject to "Subject" -- the subject
    	set theContent to "Content" -- the content
    	set theAddress to "xxx@163.com" -- the receiver 
    	set theSignatureName to "signature_name"-- the signature name
    	set theAttachmentFile to "Macintosh HD:Users:moligaloo:Downloads:attachment.pdf" -- the attachment path
     
    	set msg to make new outgoing message with properties {subject: theSubject, content: theContent, visible:true}
     
    	tell msg to make new to recipient at end of every to recipient with properties {address:theAddress}
    	tell msg to make new attachment with properties {file name:theAttachmentFile as alias}
     
    	set message signature of msg to signature theSignatureName
     
    	send msg
    end tell
    Thanks for your help!
     
  2. vloryan thread starter macrumors member

    Joined:
    Jan 11, 2014
    #3
    i know how to use variables in Automator, but i do not know how to use those Automator variables within the "Run AppleScript" action?!
     
  3. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #4
    What have you tried googling? Searching for "automator variable in applescript" yielded useful results for me...
     
  4. vloryan thread starter macrumors member

    Joined:
    Jan 11, 2014
  5. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
  6. Red Menace macrumors 6502

    Red Menace

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #7
    Automator is scriptable, so if you are running a workflow (not an application), you can also access its variables with something like:

    Code:
    get value of variable "email" of front workflow
     
  7. vloryan thread starter macrumors member

    Joined:
    Jan 11, 2014
    #8
    thanks RED MENACE! sorry for asking, but how would this look like in that script?

    Code:
    tell application "Mail"
     
    	set theSubject to "Subject" -- the subject
    	set theContent to "Content" -- the content
    	set theAddress to "xxx@163.com" -- the receiver 
    	set theSignatureName to "signature_name"-- the signature name
    	set theAttachmentFile to "Macintosh HD:Users:moligaloo:Downloads:attachment.pdf" -- the attachment path
     
    	set msg to make new outgoing message with properties {subject: theSubject, content: theContent, visible:true}
     
    	tell msg to make new to recipient at end of every to recipient with properties {address:theAddress}
    	tell msg to make new attachment with properties {file name:theAttachmentFile as alias}
     
    	set message signature of msg to signature theSignatureName
     
    	send msg
    end tell
    thanks!
     
  8. Red Menace macrumors 6502

    Red Menace

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #9
    You didn't mention where you are wanting to use the variable, but for the message contents, as an example, it would be something like:

    Code:
    tell application "Mail"
    	set theSubject to "Subject" -- the subject
    	tell application "Automator" to set theContent to value of variable "email" of front workflow -- the content
    	set theAddress to "xxx@163.com" -- the receiver 
    	
    	-- rest of script ...
     
  9. vloryan thread starter macrumors member

    Joined:
    Jan 11, 2014
    #10
    thanks for your work! the variable (email) is the address of the recipient. Can i simply replace "xxx@163.com" with "theContent"?
     
  10. vloryan thread starter macrumors member

    Joined:
    Jan 11, 2014
    #11
    Thanks so much Red Menace. Got it. After many hours :)

    Code:
    tell application "Mail"
    	
    	set theSubject to "Subject" -- the subject
    	set theContent to "Content" -- the content
    	tell application "Automator" to set theAddress to value of variable "email" of front workflow -- the content
    	
    	
    	set theSignatureName to "signature_name" -- the signature name
    	set theAttachmentFile to "Macintosh HD:Users:moligaloo:Downloads:attachment.pdf" -- the attachment path
    	
    	set msg to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}
    	
    	tell msg to make new to recipient at end of every to recipient with properties {address:theAddress}
    	tell msg to make new attachment with properties {file name:theAttachmentFile as alias}
    	
    	set message signature of msg to signature theSignatureName
    	
    	send msg
    end tell
    Thanks for your help!
     

Share This Page