Launchd.plist with WatchPaths key: How to set a minimum interval?

佐手、 提交于 2019-12-05 00:11:34

问题


How would one set a minimum interval for a launchd.plist script with a WatchPath key?

For example, I want to run a script every time new files appear in a directory, but I would like it to only run once an hour at maximum.

The launchd.plist might look something like this:

<?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>org.me.pytag</string>
  <key>ProgramArguments</key>
  <array>
    <string>/Users/me/bin/pytag.py</string>
  </array>
  <key>WatchPaths</key>
  <array>
    <string>/Volumes/Data/Media/Video/Processing/Converted</string>
  </array>
  <key>StandardOutPath</key>
  <string>/dev/null</string>
</dict>
</plist>

回答1:


Add this property. Note that the integer is in seconds.

<key>ThrottleInterval</key>
  <integer>3600</integer>


来源:https://stackoverflow.com/questions/3272398/launchd-plist-with-watchpaths-key-how-to-set-a-minimum-interval

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!