Stochastic Nonsense

Put something smart here.

Useful OSX Utilities for Working in Bash

OS X has a bunch of os-specific utilities that make working in bash just a bit nicer.

To turn a date in seconds into a human readable date, use:

convert a date in seconds to human readable
1
2
$ date -r 1334500523
Sun Apr 15 07:35:23 PDT 2012

You can use pbcopy to copy something into the clipboard. So for example, cat a file and place it in the system copy buffer:

pbcopy copies to clipboard
1
$ cat ./myfile | pbcopy

Similarly, pbpaste will paste from the clipboard, so to write the contents of your clipboard to a file:

pbpaste copies from the clipboard
1
$ pbpaste > myfile

To notify yourself after a long job has finished, for example uploading a new jar to a remote server, you can use say to have a voice read words to you over the speakers or use growlnotify to send yourself a growl message:

notifications
1
2
3
4
5
$ say "done"
$
$ # or
$
$ growlnotify -m "done"

(growl unfortunately started charging money which is somewhat annoying, though 1.2.2 seems to still work)

so for example:

1
$ rsync --progress output/job.jar $HOST/job.jar && say "done" && growlnotify "done"

To open the current directory in finder:

open the current directory
1
$ open .

If you add an external drive such as a usb stick, the mount point is in /Volumes:

1
2
3
4
5
laptop:~ earl$ ll /Volumes/
total 8
drwxrwxrwt@  3 root  admin   102B May 21 23:04 .
drwxr-xr-x  31 root  wheel   1.1K May 21 23:28 ..
lrwxr-xr-x   1 root  admin     1B May 14 13:09 Macintosh HD -> /

You can use spotlight from the command line as well with mdfind:

use spotlight from bash
1
2
3
4
5
$ mdfind macintosh | head -4
/Users/earl/Library/Application Support/TextWrangler/TextWrangler User Manual (4.0).pdf
/opt/local/include/lzo/lzodefs.h
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/scons-2.0.1/SCons/compat/_scons_subprocess.py
/opt/local/share/doc/boost/libs/ratio/example/config.hpp

And finally, you can create screenshots with screencapture.

trigger screenshot from bash
1
$ screencapture capture.png