文件在目录中更改时执行命令


5

在OS X中,有没有办法(shell script-ish?)来查看文件模式的目录,是否有任何文件更改来执行命令?


虽然不需要,但可能有一个例子:您想要观看哪些文件以及应该用它们做些什么?您是否仅限于使用命令行,还是也可以使用AppleScript?
slhck 2011年

Answers:


4

有一个应用程序:

/System/Library/CoreServices/Folder Actions Setup.app

选择要观看的文件夹和要执行的脚本。您也可以编辑脚本。


5

~/Library/LaunchAgents/watch.and.lol.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>watch.and.lol</string>
    <key>ProgramArguments</key>
    <array>
        <string>say</string>
        <string>lol</string>
    </array>
    <key>WatchPaths</key>
    <array>
        <string>~/Desktop</string>
    </array>
</dict>
</plist>

launchctl load ~/Library/LaunchAgents/watch.and.lol.plist 或重新登录以加载代理。

有一个启动的问题«管理OS X虽然:

事实证明,如果文件被列为启动作业WatchPath,它必须始终存在,或者launchd从其要查看的路径列表中删除路径。所以你不能注意创建某个文件; 您只能观察文件的更改。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.