Min*_*int 268 macos watch inotify
我想在我的Mac(Snow Leopard)上观看一个文件夹,然后执行一个脚本(给它一个刚刚移入文件夹的文件名(作为参数... x.sh"filename")).
我有一个用bash(x.sh)编写的脚本,它会在输入$ 1上移动一些文件和其他东西我只需要OSX在新文件/文件夹被移动/创建到目录时给我文件名.
有这样的命令吗?
cwd*_*cwd 418
fswatch是一个使用Mac OS X FSEvents API监视目录的小程序.当收到有关该目录的任何更改的事件时,将执行指定的shell命令/bin/bash
如果您使用的是GNU/Linux,则
inotifywatch(inotify-tools大多数发行版中的软件包的一部分
)提供类似的功能.
更新: fswatch现在可以在许多平台上使用,包括BSD,Debian和Windows.
可以观看多个路径的新方法 - 适用于1.x及更高版本:
fswatch -o ~/path/to/watch | xargs -n1 -I{} ~/script/to/run/when/files/change.sh
Run Code Online (Sandbox Code Playgroud)
注意:如果不是,则输出的数字
-o将被添加到xargs命令的末尾-I{}.如果您确实选择使用该号码,请将其{}放在命令的任何位置.
版本0.x的旧方法:
fswatch ~/path/to/watch ~/script/to/run/when/files/change.sh
Run Code Online (Sandbox Code Playgroud)
截至2013年12月9日,它已被添加回自制软件 - yay!因此,更新您的公式列表(brew update),然后您需要做的就是:
brew install fswatch
Run Code Online (Sandbox Code Playgroud)
在中键入这些命令 Terminal.app
cd /tmp
git clone https://github.com/alandipert/fswatch
cd fswatch/
make
cp fswatch /usr/local/bin/fswatch
Run Code Online (Sandbox Code Playgroud)
如果您c的系统上没有编译器,则可能需要安装Xcode或Xcode命令行工具 - 两者都是免费的.但是,如果是这种情况,你应该只看看自制软件.
fswatch版本1.x的其他选项Usage:
fswatch [OPTION] ... path ...
Options:
-0, --print0 Use the ASCII NUL character (0) as line separator.
-1, --one-event Exit fsw after the first set of events is received.
-e, --exclude=REGEX Exclude paths matching REGEX.
-E, --extended Use exended regular expressions.
-f, --format-time Print the event time using the specified format.
-h, --help Show this message.
-i, --insensitive Use case insensitive regular expressions.
-k, --kqueue Use the kqueue monitor.
-l, --latency=DOUBLE Set the latency.
-L, --follow-links Follow symbolic links.
-n, --numeric Print a numeric event mask.
-o, --one-per-batch Print a single message with the number of change events.
in the current batch.
-p, --poll Use the poll monitor.
-r, --recursive Recurse subdirectories.
-t, --timestamp Print the event timestamp.
-u, --utc-time Print the event time as UTC time.
-v, --verbose Print verbose output.
-x, --event-flags Print the event flags.
See the man page for more information.
Run Code Online (Sandbox Code Playgroud)
sak*_*kra 90
您可以将launchd用于此目的.Launchd可以配置为在修改文件路径时自动启动程序.
例如,以下launchd config plist将在/usr/bin/logger修改我的用户帐户的桌面文件夹时启动该程序:
<?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>logger</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/logger</string>
<string>path modified</string>
</array>
<key>WatchPaths</key>
<array>
<string>/Users/sakra/Desktop/</string>
</array>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud)
要激活配置plist,请将其保存到Library文件夹中的LaunchAgents文件夹,作为"logger.plist".
然后,您可以使用该命令launchctl通过运行以下命令激活logger.plist:
$ launchctl load ~/Library/LaunchAgents/logger.plist
Run Code Online (Sandbox Code Playgroud)
现在正在监视桌面文件夹.每次更改时,您都应该在system.log中看到输出(使用Console.app).要停用logger.plist,请运行:
$ launchctl unload ~/Library/LaunchAgents/logger.plist
Run Code Online (Sandbox Code Playgroud)
上面的配置文件使用该WatchPaths选项.或者,您也可以使用该
QueueDirectories选项.有关更多信息,请参见launchd手册页.
Jak*_*olý 31
Facebook的守望者,通过Homebrew提供,也看起来不错.它还支持过滤:
这两行在源目录上建立监视,然后设置名为"buildme"的触发器,每当CSS文件发生更改时,该触发器将运行名为"minify-css"的工具.该工具将传递更改的文件名列表.
$ watchman watch ~/src
$ watchman -- trigger ~/src buildme '*.css' -- minify-css
请注意,路径必须是绝对的.
$ while true; do kqwait ./file-to-watch.js; script-to-execute.sh; done
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
111710 次 |
| 最近记录: |