代码之家  ›  专栏  ›  技术社区  ›  Nicolas

从launchd/launctl运行osascript(applescript)

  •  1
  • Nicolas  · 技术社区  · 7 年前

    我正在尝试使用 launchd 代理,但除了将applescript内容写入 stdout .

    我的 发射装置 代理 ~/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 发射装置 探员们又来了?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Mark Setchell    7 年前

    我认为你是双重特写!

    你需要:

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

    还有:

    launchctl start com.nn.test