I have the following script to take a screenshot programmatically
$ cat /Users/bamboo/capture/capture #!/bin/bash screencapture -o "$(dirname "$0"