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

vloryan

macrumors member
Original poster
Jan 11, 2014
57
0
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!
 
Last edited:

vloryan

macrumors member
Original poster
Jan 11, 2014
57
0
i know how to use variables in Automator, but i do not know how to use those Automator variables within the "Run AppleScript" action?!
 

Red Menace

macrumors 6502a
May 29, 2011
578
226
Colorado, USA
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
 

vloryan

macrumors member
Original poster
Jan 11, 2014
57
0
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!
 

Red Menace

macrumors 6502a
May 29, 2011
578
226
Colorado, USA
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 ...
 

vloryan

macrumors member
Original poster
Jan 11, 2014
57
0
thanks for your work! the variable (email) is the address of the recipient. Can i simply replace "xxx@163.com" with "theContent"?
 

vloryan

macrumors member
Original poster
Jan 11, 2014
57
0
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!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.