Skip to content

Instantly share code, notes, and snippets.

@ftf
Created April 17, 2012 19:44
Show Gist options
  • Save ftf/2408550 to your computer and use it in GitHub Desktop.
Save ftf/2408550 to your computer and use it in GitHub Desktop.
make screenshot, save locally, upload, copy URL to clipboard
#!/usr/bin/env bash
# intended use as alfred extension
# if used otherwise take care of the {query} parameter string
#
# Edit paths for lefolder and
#
# at first, check if ~/Pictures/lescreenshots exists, if not create
# grabs a screenshot or takes a existing image as input
#
# if {query} (alfred parameter placeholder); then
# is a filename - don't create a new screenshot
# is t - take a screenshot with a 5 seconds timer, e.g. usefull for
# pulling up menus, etc
# is s - opens image with skitch - what else to use for arrows?
# is p - opens image with pixelmator
# is pt or st - do a timed screenshot and open with pixelmator / skitch
# is b - copy to my octopress installation, no upload
#
# if you want to use different applications, change the parameter and paths below
#
# generate a random filename with uuidgen
# create screenshot or copy parameter file to lescreenshots; use generated name
# upload file with scp
# copy remote url to clipboard
############ configuration
lefolder=~/Pictures/lescreenshot # local directory for screenshots
scphost=tesserakt # scp host, for port, user and password use ~/.ssh/config
scpdirectory='~/sharepoint/img/skitch' # directory to scp to
webpath=http://fabianfranke.de/sharepoint/img/skitch # web path of that directory
octopressdirectory=~/Development/octopress/source/media # your octopress, blog, whatever directory
leparameter={query} # alfred parameter placeholder - change only needed when not using alfred
############ end configuration
PATH=/usr/local/bin:$PATH
dothegrowl ()
{
# using hash to check if growlnotify is in path, if
# yes, fire a notification with the Skitch icon
hash growlnotify 2>/dev/null && growlnotify -t autoshot -n autoshot -I /Applications/Skitch.app/ -m "$@"
}
if [ ! -d $lefolder ]; then
mkdir -p $lefolder
fi
leshotopts=""
leedit=wedontneednoedititation
dotheshot=true
deliverytarget=upload
if [[ $leparameter ]]; then
if [ -f "$leparameter" ]; then
# if paramter is a file, don't take a new screenshot
dotheshot=false
else
case "$leparameter" in
t)
leshotopts='-T 5'
;;
p)
leedit='pixelmator'
;;
pt)
leshotopts='-T 5'
leedit='pixelmator'
;;
s)
leedit=skitch
;;
st)
leshotopts='-T 5'
leedit=skitch
;;
b)
deliverytarget=blog
;;
bp)
deliverytarget=blog
leedit='pixelmator'
;;
bpt)
deliverytarget=blog
leshotopts='-T 5'
leedit='pixelmator'
;;
*)
dothegrowl "parameter or invalid file, please try again"
exit
;;
esac
fi
fi
cd $lefolder
lefilename=`uuidgen | md5`.png
# take a new screenshot or should we copy a existing file
if [[ $dotheshot == true ]]; then
screencapture $leshotopts -i $lefilename
if [ ! -e "$lefilename" ]; then
# no new file? suppose user has cancled screenshot
dothegrowl "screenscapture cancled or something bad happend"
exit
fi
else
cp "$leparameter" $lefolder/$lefilename
fi
# should we open the screenshot with an enditor?
if [[ $leedit == 'picturesque' ]]; then
open -W -a "Picturesque" $lefilename
elif [[ $leedit == 'skitch' ]]; then
open -W -a 'Skitch' $lefilename
elif [[ $leedit == 'pixelmator' ]]; then
open -W -a "Pixelmator" $lefilename
fi
# upload or copy to our blog directory
if [[ $deliverytarget == "blog" ]]; then
mv $lefilename $octopressdirectory/
printf '/media/'$lefilename | pbcopy
else
scp $lefilename $scphost:$scpdirectory
printf $webpath/$lefilename | pbcopy
fi
dothegrowl "Screenshot uploaded, URL ready for pasting, finest of sirs."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment