Last active
May 23, 2020 15:57
-
-
Save jeff-sternberg/e805cfb139cf50ccbab44ea99adefae1 to your computer and use it in GitHub Desktop.
Demo AppleScript for making web versions of print images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- examples, replace with yours | |
set print_images to ¬ | |
{"/Users/jeffsternberg/Desktop/catalog/image_1.psd", ¬ | |
"/Users/jeffsternberg/Desktop/catalog/image_2.psd"} | |
-- main loop | |
repeat with print_image in print_images | |
process_image(print_image) | |
end repeat | |
-- convert an image to RGB, then save 4 smaller web friendly JPEGs | |
on process_image(print_image) | |
set image_name to remove_extension(print_image) | |
tell application "Adobe Photoshop 2020" | |
open file print_image | |
tell current document | |
change mode to RGB | |
repeat with new_width in {600, 400, 200, 100} | |
tell me to make_web_copy(image_name, new_width) | |
end repeat | |
close without saving | |
end tell | |
end tell | |
end process_image | |
-- resize, save as jpeg, revert | |
on make_web_copy(image_name, new_width) | |
tell application "Adobe Photoshop 2020" | |
tell current document | |
set revert_state to the current history state | |
resize image width new_width ¬ | |
resample method bicubic smoother | |
save as JPEG in file (image_name & "_" & new_width) ¬ | |
appending lowercase extension with copying | |
set the current history state to revert_state | |
end tell | |
end tell | |
end make_web_copy | |
-- from http://www.macosxautomation.com/applescript/sbrt/index.html | |
on remove_extension(this_name) | |
if this_name contains "." then | |
set this_name to ¬ | |
(the reverse of every character of this_name) ¬ | |
as string | |
set x to the offset of "." in this_name | |
set this_name to (text (x + 1) thru -1 of this_name) | |
set this_name to ¬ | |
(the reverse of every character of this_name) ¬ | |
as string | |
end if | |
return this_name | |
end remove_extension |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment