Mail Rules with javascript instead of applescript

谁都会走 提交于 2019-12-13 01:45:05

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/49117223/mail-rules-with-javascript-instead-of-applescript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!