我有一个文件夹,我想在其中添加文件夹操作。当文件添加到顶层时,该操作效果很好。但是当文件添加到子文件夹时,该操作未启用。有没有办法确保当文件添加到其任何子文件夹时启用文件夹操作?
答案1
启动有一个功能叫做监视路径当发生变化时它可以运行.sh 脚本或者任何你想要的脚本。
取决于您要监控的路径的安全要求以及您希望何时监控(登录时还是始终?);确定放置 plist 的位置。
~/Library/LaunchAgents Per-user agents provided by the user.
/Library/LaunchAgents Per-user agents provided by the administrator.
/Library/LaunchDaemons System-wide daemons provided by the administrator.
/System/Library/LaunchAgents Per-user agents provided by Mac OS X.
/System/Library/LaunchDaemons System-wide daemons provided by Mac OS X.
例子:~/Library/LaunchAgents/com.tellemewhen.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.tellemewhen.plist</string>
<key>OnDemand</key>
<true/>
<key>Program</key>
<string>/PATH/TO/YOURSCIPTTORUN.sh</string>
<key>ProgramArguments</key>
<array>
<string></string>
</array>
<key>WatchPaths</key>
<array>
<string>/path/to/watch</string>
</array>
</dict>
</plist>
launchctl load ~/Library/LaunchAgents/com.tellemewhen.plist
加载 plist。