#!/bin/bash # scr - for os x # Takes a screenshot, resizes it, and uploads it to a webpage. It's meant to # be run with cron, by customizing and adding the following line to your # crontab: # # */1 * * * * /Path/to/scr 0 > /dev/null 2>&1 # # that line will run scr, with no delay, once a minute. once it is added it # can be "turned on and off" within the script. # run scr with no options for help. ############################################################################ # defaults: # Where we want to upload the jpg, user@server:path/to/file.jpg # Width of resized jpg LOCATION="cutup@cutup.org:cutup.org/screen.jpg" WIDTH="350" ########################################################################### # status function status { if [ "$(crontab -l | awk '/scr/' | awk '/^#/')" ]; then echo " off" else echo " on" fi } # comment crontab entry out function cronoff { crontab -l | sed '/\/scr /s/^/#/' > tempcron crontab tempcron rm tempcron crontab -l } # uncomment crontab entry function cronon { crontab -l | sed '/\/scr /s/^#//' > tempcron crontab tempcron rm tempcron crontab -l } # capture and upload function capture { sleep "$1" try=$(ps -c -U $(whoami) | awk '/ScreenSaver/') if [ "$try" ]; then echo "screensaver on" else /usr/sbin/screencapture -C temp_screen_cap.jpg /usr/bin/sips --resampleWidth "$2" --setProperty format jpeg --setProperty formatOptions low temp_screen_cap.jpg --out "temp_screen_cap.jpg" scp "temp_screen_cap.jpg" "$3" rm "temp_screen_cap.jpg" fi } # help message function help { cat << EOF $(basename $0) [ on | off | ? | delay [width] [location] ] takes snapshot and uploads it delay - in seconds width - width in pixels of resulting jpg, delay must be set location - full path to remote location, size and delay must be set on - uncomments entry in crontab off - comments out entry in crontab ? - status of crontab (off or on) EOF } case "$1" in "?" ) status ; exit;; "on" ) cronon ; exit;; "off" ) cronoff ; exit;; esac if [ $1 ] && [ $2 ] && [ $3 ]; then capture $1 $2 $3 elif [ $1 ] && [ $2 ]; then capture $1 $2 $LOCATION elif [ $1 ]; then capture $1 $WIDTH $LOCATION else help $0 fi