Skip to content

Instantly share code, notes, and snippets.

@alexwlchan
Created May 1, 2013 11:33
Show Gist options
  • Save alexwlchan/5494842 to your computer and use it in GitHub Desktop.
Save alexwlchan/5494842 to your computer and use it in GitHub Desktop.
This is a quick AppleScript written to shrink wide images to at most 1200px. To use it, open it in Script Editor, then save it as an Application, and drag files on to its icon in Finder. Target width is set in line 17. We can similarly use it to shrink tall images if we want to.
on open some_images
repeat with my_image in some_images
try
rescale_and_copy(my_image)
end try
end repeat
end open
to rescale_and_copy(my_item)
tell application "Image Events"
launch
-- Change the width as appropriate here
set the target_width to 1200
-- Open the image
set my_image to my_item
set my_type to my_image's file type
copy dimensions of this_image to {current_width, current_height}
-- Scale the image as appropriate
if current_width is greater than target_width then
scale my_image to size target_width
end if
-- Make a new copy with the prefix "scaled"
tell application "Finder" to set new_item to ¬
(container of my item as string) & "scaled." & (name of my_item)
save my_image in new_item as my_type
end tell
end rescale_and_copy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment