Mail Rules with javascript instead of applescript

2019-07-27 05:23发布

In a Mac mail rule, I am trying to run a javascript instead of an applescript. This has been asked in Mail Rules using JavaScript for Automation instead of AppleScript but the answer is not working for me!

I have tried to simplify the code as much as I can. So, the following applescript works fine:

on perform mail action with messages theMessages 
    say "running!"
end perform mail action with messages

but the equivalent javascript is not working.

function performMailActionWithMessages(messages) {
    app = Application.currentApplication()
    app.includeStandardAdditions = true
    app.say ("running")
}

Edit Here are my rule parameters

mail2.scpt

rule configuration

1条回答
祖国的老花朵
2楼-- · 2019-07-27 05:59

I do it without getting app. Try something like…

// ObjC.import('Cocoa')
ObjC.import('stdlib')
var program="/usr/bin/say"
function performMailActionWithMessages(messages) {
    say("running")
}
function say(what){
    var command = program + " '"+what+"'"
    console.log(command)
    $.system(command)
}

I’m not sure you need cocoa. You probably need stdlib.

查看更多
登录 后发表回答