Easy iPhone Simulator Screenshots

by @jehiah on 2009-10-07 16:03
Filed under: 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:

[code]
#!/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
[/code]

You can download the current version on bitbucket

Subscribe via RSS ı Email
© 2017 - Jehiah Czebotar