Skip to content

Instantly share code, notes, and snippets.

@chris-79
Last active November 20, 2015 15:51
Show Gist options
  • Save chris-79/26b9d8ed7c4821633e4c to your computer and use it in GitHub Desktop.
Save chris-79/26b9d8ed7c4821633e4c to your computer and use it in GitHub Desktop.
Screen Shot Prettifier

Screen Shot Prettifier

This is a short shell script (inspired by Dr. Drang) that makes Mac screen shots a bit nicer than normal.

Why?

I find OS X's screen shots to be a bit annoying in a few ways:

  • The large drop shadow on whole-window screen shots is way too large.
  • Having zero drop shadows on all other screen shots is boring.
  • Showing the background app or desktop image in a screen shot seems messy.
  • Retina-sized screen shots turn out to be WAY too large.

Dependencies

This script relies on 3 things to make it actually work:

These all super simple to install if you're already running homebrew*...

$ brew install imagemagick
$ brew install pngquant
$ brew cask install node
$ npm install -g imageoptim-cli

* Yes, this uses homebrew to install node.

The Setup

Using Hazel and OnyX

Note: These are not required to make the shell script actually work, but they sure do make life a bit easier :)

First things first. To get rid of the window drop shadows, I used OnyX to switch them off. While I was there, I also re-reouted where my screen shots are saved. By default, they're on the ~/Desktop.

Next, I installed Hazel to watch my screen shot output folder. It's not a free app, but I find it quite invaluable and well worth the $30 price tag.

Hazel settings:

  • Add + the folder where screen shots are placed. (Again, by default they're output to your ~/Desktop folder.)
  • Add + a new Rule and name it whatever you'd like. Mine's called "Screen Shot Handler".

For the conditions, leave "If all of the following [...]" alone.

  • Change the first rule to: Name starts with "Screen". Then click +
  • Add: Name contains "Shot". Then click +
  • Add: Name does not start with "Screen-Shot". Then click +
  • Add: Date Last Modified is in the last "1" Minute

For "Do the following [...]"

  • Display notification with pattern: "Processing file". Click +
  • Run shell script embedded script. Click +
  • Display notification with pattern: "Your Screen Shot is ready!"

Screen Shot

  • Go back up to Run shell script and click "Edit Script"
  • Shell: /bin/bash
  • Paste the shell script in the window

Script window

  • Save your work

Support

None!

## PREREQUISITES:
# brew install imagemagick
# brew install pngquant
# brew cask install node
# npm install -g imageoptim-cli
function getGreaterOfHW { # Returns the largest size of the image (it's width or height)
local width=`identify -format %w $@`
local height=`identify -format %h $@`
[ $width -gt $height ] && dim=$width || dim=$height
return $dim
}
# Remove "at " from the name and change spaces to dashes
NEWIMG=$(echo "$1" | sed 's|at ||g' | sed 's| |-|g')
# if the modified image already exists, delete it
if [ -e $NEWIMG ]; then rm -rf $NEWIMG; fi
# Duplicate the image
cp "$1" $NEWIMG
# Shrink the image by half and round the corners a bit
convert $NEWIMG -scale 50% \( +clone -alpha extract -draw 'fill black polygon 0,0 0,3 3,0 fill white circle 3,3 3,0' \( +clone -flip \) -compose Multiply -composite \( +clone -flop \) -compose Multiply -composite \) -alpha off -compose CopyOpacity -composite $NEWIMG
# Give it a small drop shadow and a fake blue (#497ABC) background
convert $NEWIMG \( +clone -background black -shadow 60x5+0+2 \) +swap -background "#497ABC" -layers merge +repage $NEWIMG
# Initial compression attempt
mogrify -filter Triangle -define filter:support=2 -thumbnail `getGreaterOfHW $NEWIMG` -unsharp 0.25x0.08+8.3+0.045 -dither None -posterize 136 -quality 82 -define jpeg:fancy-upsampling=off -define png:compression-filter=5 -define png:compression-level=9 -define png:compression-strategy=1 -define png:exclude-chunk=all -interlace none -colorspace sRGB $NEWIMG && \ q $NEWIMG
# More compression
pngquant --quality=65-80 --ext .png --force $NEWIMG
# Even MORE compession
ls $NEWIMG | imageOptim --image-alpha
# Show me the money! err... file
open -R $NEWIMG
osascript -e 'tell application "Finder" to set the current view of Finder window 1 to list view'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment