简体   繁体   中英

Pass the body of an email to AppleScript

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM