javascript - 使用 javascript 而不是 applescript 的邮件规则

标签 javascript applescript javascript-automation apple-mail

在 Mac 邮件规则中,我尝试运行 javascript 而不是 applescript。这已在 Mail Rules using JavaScript for Automation instead of AppleScript 中提出但答案对我不起作用!

我已尽力简化代码。因此,以下 applescript 可以正常工作:

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

但等效的 javascript 不起作用。

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

编辑 这是我的规则参数

mail2.scpt

rule configuration

最佳答案

我没有获得应用程序就这样做了。尝试类似...

// 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)
}

我不确定你需要 cocoa 。您可能需要标准库。

关于javascript - 使用 javascript 而不是 applescript 的邮件规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49117223/

相关文章:

c# - 一些第三方工具的 Javascript 和 CSS 文件压缩技术

safari - 如何通过 AppleScript 在 Safari 中安装扩展

javascript - 如何滚动某个 div?

applescript - 在我的脚本中使用 UI 元素会出现 "Expected class name but found identifier."语法错误

c - 如何评估是否存在外接显示器

javascript - 如何在 macOS 预览应用程序中使用 JavaScript for Automator (JXA) 保存图像?

javascript - 无法转换类型

macos - 如何在 JavaScript for Automation 中获取当前脚本文件夹的 POSIX 路径?

javascript - 连接 AlpineJS x-text 和 HREF 属性的问题

javascript - Bootstrap 使用 Modal 使用 bundleconfig 时在哪里放置 jquery 和 bootstrap