Easy iPhone Simulator Screenshots

posted October 7th 2009 at 1603 EDT in All, Programming, iPhone, mobile

If you are a developer like me, you often need to take screenshots of your application for use on your website, in ads, or more often for upload to iTunes Connect for display in the AppStore.

For a long time I've just muddled through with option+shift+3 which allows you to take a screenshot of a specific region, and then i select the specific 480x320 pixels that i want from the iPhone Simulator to get my screenshot.

It's tedious to select exactly those pixels though, and far to often i find myself off by a pixel in size, or i select the wrong pixels. If i'm off by a pixel iTunes connect won't even allow me to upload the screenshot!

One way to take 'perfect' screenshots all the time is with a running device and to take them through the Xcode Organizer. This is still frustrating to me though because i have to switch back and forth between my computer and a physical device, and because it isn't as easy to set specific things like the the Agency text and the Date Time display with SimFinger.

The solution I've come up with is to use the built in command line utility screenshot combined with sips (a command line image parser).

I use screenshot to take a screenshot of the whole iPhone Simulator (frame and all) then I use sips to strip out the frame to get just the device screen.

I've wrapped this in a script which also gives me an easy spot to name the screenshot. It ends up like this:


#!/bin/sh

# script to screenshot the iPhone Simulator to the correct size
# to upload to iTunes Connect
# written by Jehiah Czebotar http://jehiah.cz/

OUTPUTDIR=~/Desktop
TEMPFILE=iPhoneSimulatorScreenshot_`date +%Y%m%d_%H%M%S`.png

echo "output filename:\c"
read -e OUTPUTFILE

# activate iPhone Simulator so its easy to click on
osascript -e 'tell application "iPhone Simulator"' -e 'activate' -e 'end tell'

# capture the screen
screencapture -iowW $OUTPUTDIR/$TEMPFILE

# resize to the apple upload size, 320x480
sips -c 480 320 $OUTPUTDIR/$TEMPFILE --out $OUTPUTDIR/$OUTPUTFILE
 

You can download the current version on bitbucket

4 Responses

  1. #1 Emanuele Cipolloni
    5 months ago

    Cool snippet! thanx!

  2. #2 Anurag
    4 months, 2 weeks ago

    Neat stuff. saved me a lot of time!

  3. #3 Jonathan W
    4 months, 1 week ago

    Sweet. I generally do Apple-Shift-Option-4 (using the 4 key rather than 3 lets you draw a box can capture only a part). Holding down ‘option’ copies it to your clipboard rather than saving it to the desktop).

    Then i paste it into a photoshop document that’s 460×320 to crop it perfectly without the possibility of being too tall or wide.

  4. #4 Jehiah
    4 months, 1 week ago

    @Jonathan, that is a fair methodology, but i don’t find it very fast to fire up Photoshop and crop each image when i can have that done for me.

    You are right though that cropping in Photoshop gives you more control and helps solve the one-pixel-off problems i was having continually.