开发者

Pass the body of an email to AppleScript

开发者 https://www.devze.com 2022-12-30 05:32 出处:网络
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.

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.

Tha开发者_如何转开发nks 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
0

精彩评论

暂无评论...
验证码 换一张
取 消