‘watch’ Command For OS X

I just discovered today that the ‘watch’ command isn’t natively available on OS X. You can apparently get it through Macports. Since I don’t have Macports installed, this seemed like a very heavy solution for a rather small problem.

Looking for another solution, I opted for a basic while loop — which is a shell command. My basic command is going to look something like:

while echo "This prints every 5 seconds" ; do clear ; sleep 5 ; done

It’s not as useful as watch in that you don’t have the additional time output, but it definitely works and doesn’t require any additional installs to get the data from the command line.

For the creative and motivated, it probably wouldn’t be difficult to make a very simple wrapper script to more closely match the watch output by leveraging a while loop. You’re probably better off just getting a compiled binary at that point, but it might be an interesting exercise regardless.

Sep 26th, 2009 | Posted in IT, Nerd
No comments yet.

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>