Pass AppleScript Body

I have Mail configured to run AppleScript when it receives an email with the subject line "AppleScript", and I was wondering how I can pass the body of this email to a script for execution.

Thanks in advance!

+3
source share
1 answer

The body of the message can determine my use of the property of the contentmessage that was passed to the rule. To execute the script, use the command run script.

The following script example is an example of writing AppleScript that can be attached as an action of a rule that will process the message body as 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
+5
source

Source: https://habr.com/ru/post/1745135/


All Articles