Skip to content

Instantly share code, notes, and snippets.

@robmooney
Created April 18, 2012 14:00
Show Gist options
  • Save robmooney/2413786 to your computer and use it in GitHub Desktop.
Save robmooney/2413786 to your computer and use it in GitHub Desktop.
An AppleScript for cropping the iOS status bar out of screenshots in Photoshop.
property iphone_portrait : {w:320, h:480}
property iphone_landscape : {w:480, h:320}
property iphone_2x_portrait : {w:640, h:960}
property iphone_2x_landscape : {w:960, h:640}
property ipad_portrait : {w:768, h:1024}
property ipad_landscape : {w:1024, h:768}
property ipad_2x_portrait : {w:1536, h:2048}
property ipad_2x_landscape : {w:2048, h:1536}
tell application id "com.adobe.Photoshop"
-- set ruler units to pixels
set current_ruler_units to the ruler units of settings
set ruler units of settings to pixel units
set doc to the current document
-- work around for bug where non integral resolutions cause the script to fail
resize image doc ¬
resolution 72 ¬
resample method none
set doc_size to {w:width of doc, h:height of doc}
set resize_successful to false
if doc_size is equal to iphone_portrait or ¬
doc_size is equal to iphone_landscape or ¬
doc_size is equal to ipad_portrait or ¬
doc_size is equal to ipad_landscape then
resize canvas doc ¬
width (w of doc_size) ¬
height (h of doc_size) - 20 ¬
anchor position bottom center
set resize_successful to true
else if doc_size is equal to iphone_2x_portrait or ¬
doc_size is equal to iphone_2x_landscape or ¬
doc_size is equal to ipad_2x_portrait or ¬
doc_size is equal to ipad_2x_landscape then
resize canvas doc ¬
width (w of doc_size) ¬
height (h of doc_size) - 40 ¬
anchor position bottom center
set resize_successful to true
else
display alert "Unknown iOS screen resolution."
end if
if resize_successful then
try
set exported_file to choose file name
export doc in (exported_file as text) ¬
as save for web ¬
with options {web format:PNG, png eight:false}
end try
end if
-- restore ruler units
set ruler units of settings to current_ruler_units
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment