使用启动代理检测Mac应用程序已移至垃圾箱文件夹

时间:2014-02-15 07:32:53

标签: macos shell applescript launchd

当我的应用程序移动到垃圾文件夹时,我想运行一个脚本,并且我知道使用启动代理可能,我用Google搜索并制作了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.meet.anywhere</string>
    <key>WatchPaths</key>
    <array>
        <string>~/.Trash</string>
    </array>
    <key>ProgramArguments</key>
    <array>
        <string>/Users/eclit/Desktop/DeleteScript.scpt</string>
    </array>
    <key>KeepAlive</key>
    <false/>
</dict>
</plist>

2 个答案:

答案 0 :(得分:2)

launchd无法直接运行applescript。您需要使用命令行工具osascript来运行applescript。因此,您的ProgramArguments部分应如下所示。此外,不需要KeepAlive部分。它没有任何作用,所以我将其删除。

<key>ProgramArguments</key>
<array>
    <string>osascript</string>
    <string>/Users/eclit/Desktop/DeleteScript.scpt</string>
</array>

答案 1 :(得分:0)

<?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.meet.anywhere</string>
    <key>WatchPaths</key>
    <array>
        <string>~/.Trash/AppName.app</string>
    </array>
    <key>ProgramArguments</key>
    <array>
    <string>osascript</st
        <string>/Users/eclit/Desktop/DeleteScript.scpt</string>
    </array>
    <key>KeepAlive</key>
    <false/>
</dict>
</plist>