运行 来自 launchd / launctl 的 osascript (AppleScript)

Run osascript (AppleScript) from launchd / launctl

我正在尝试 运行 一个非常简单的 AppleScript,定期使用 launchd 代理,但除了将 AppleScript 内容写入 stdout.[=21 之外,它不会做任何事情=]

我的 launchd 经纪人 ~/Library/LaunchAgents/com.nn.test.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.nn.test</string>
    <key>ProgramArguments</key>
    <array>
      <string>/usr/bin/osascript</string>
      <string>-e</string>
      <string>"display dialog \"Hi\""</string>
    </array>
    <key>RunAtLoad</key>
    <false/>
    <key>Debug</key>
    <true/>
    <key>StartInterval</key>
    <integer>7200</integer>
    <key>StandardErrorPath</key>
    <string>/tmp/test</string>
    <key>StandardOutPath</key>
    <string>/tmp/testout</string>
</dict>
</plist>

我运行宁:

$ launchctl unload com.nn.test.plist
$ launchctl load com.nn.test.plist
$ launchctl run com.nn.test

结果是cat /tmp/testout

display dialog "Hi"

/tmp/test 为空。

预期行为 会打开一个对话框,就像我 运行 直接在 shell 中执行命令一样(有效),但似乎什么都没有正在发生。 我哪里做错了,为什么我在任何错误日志中都看不到任何错误消息?

这可能与 Mojave 的增强安全模型有关吗? AppleScript 不能再成为 launchd 代理的 运行 了吗?

我觉得你双串了!

你需要:

    <array>
    <string>/usr/bin/osascript</string>
    <string>-e</string>
    <string>display dialog "Hi"</string>
    </array>

和:

launchctl start com.nn.test