#!/bin/bash # # requirements: # - ImageMagick: http://www.imagemagick.org/script/binary-releases.php#macosx # - image_optim: https://github.com/toy/image_optim # - a scp supported host with ssh key paired # setting up the enviroment export PATH=/usr/local/bin:/opt/local/bin:/opt/local/sbin:$PATH # please change the following variable to your own: # folder: local dir for the image, default ~/Desktop/ # server: your scp server, e.g. 123.456.789.0 # username: your username for the server, e.g. root # dir: remote dir for the image, e.g. /public/www/uploads/ # url: url for the image, e.g. http://yourwebsite.com/uploads/ folder=/Users/$(whoami)/Desktop/ server=123.456.789.0 username=root dir=/public/www/uploads/ url=http://yourwebsite.com/uploads/ filename=`echo "{query}" | tr 'A-Z' 'a-z' | tr -s ' ' | tr ' ' '_'`_`date +%s`.png path=$folder$filename screencapture -i $path while [ ! -f $path ] do sleep 1 done width=`/usr/bin/osascript << EOT tell application "System Events" activate set theWidth to (display dialog "Enter the width" default answer "650") end tell set theWidth to the text returned of theWidth as integer return theWidth EOT` while [ -z "$width" ] do sleep 1 done convert $path -resize "`echo $width`x>" $path image_optim --no-pngout $path echo \![{query}]\($url$filename\) | pbcopy scp $path $username@$server:$dir echo $filename uploaded!