I want to watch a folder on my Mac (Snow Leopard) and then execute a script (giving it the filename of what was just moved into a folder (as a parameter... x.sh "filename")).
I have a script all written up in bash (x.sh) that will move some files and other stuff on input $1 I just need OSX to give me the file name when new files/folders are moved/created into a dir.
Any such command?
This is just to mention entr as an alternative on OSX to run arbitrary commands when files change. I find it simple and useful.
Here's a one-liner using
sschober
's tool.Facebook's watchman, available via Homebrew, also looks nice. It supports also filtering:
Notice that the path must be absolute.
You might want to take a look at (and maybe expand) my little tool
kqwait
. Currently it just sits around and waits for a write event on a single file, but the kqueue architecture allows for hierarchical event stacking...watchdog is a cross-platform python API for watching files / directories, and it has builtin "tricks" tool that allows you to trigger actions (including shell commands) when events occur (including new added file, removed file and changed file).
Here's a simple single line alternative for users who don't have the
watch
command who want to execute a command every 3 seconds:while :; do your-command; sleep 3; done
It's an infinite loop that is basically the same as doing the following:
watch -n3 your-command