I have Mail set up to execute an AppleScript when it receives an email with the subject "AppleScript" and I was wondering how I could pass the body of this email to the script for execution.
Thanks in advance!
I have Mail set up to execute an AppleScript when it receives an email with the subject "AppleScript" and I was wondering how I could pass the body of this email to the script for execution.
Thanks in advance!
The body of a message can determined my using the content
property of the message that has been passed to the rule action. To execute the script use the run script
command.
The following script is an example of how to write an AppleScript that can be attached as a rule action that will run the body of the message as an AppleScript:
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
repeat with theMessage in theMessages
set theBody to content of theMessage as text
my executeScript(theBody)
end repeat
end tell
end perform mail action with messages
end using terms from
on executeScript(theScript)
display alert "Run the following AppleScript?" message theScript buttons {"Cancel", "Run"}
if button returned of result = "Run" then
run script theScript
end if
end executeScript