Simple utility to run a command, and then take action if its output changes.
This can be used to monitor things, but there are probably better tools for that. I’ve primarily used it when tracking down bugs that only happen during a small percentage of invocations. Write a test that will invoke the bug, then run this and have it keep executing the test until the bug reveals itself. When it does, the output will change, and you can have it do something useful.
For example, run this on macOS
watch_when -c "date -I minutes" -x "osascript -e 'display alert "Hello" message "check the terminal"'; exit"
That will watch the output of date until the minute changes, and then alert you and exit…. and print “button returned: OK” when you click it, but that’s just a side-effect of osascript.
USAGE: watch_when -c "<command>" [-s sleep_interval] [-x "<command for when it changes>"]
-c <command> tells it what command to execute and watch
-s <seconds> tells it how long to sleep between executions
defaults to 2 seconds
-x <command> optional command to run when the output changes
The supplied command will be evaluated,
and called every 2 seconds (or sleep interval seconds
if supplied). When the output changes it will print
it out with a timestamp.
^c to stop it. or -x 'exit'
If you have terminal-notifier installed it'll try and use that
to provide additional notification.
Metadata:
Tags: