Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to Attach Script to Photoshop Action or Folder?

I'm not familiar with Applescript at all! However, I downloaded a script for use with Photoshop which crops an image to a specific format. It works great if I've got an image open in Photoshop.

What I can't figure out how to do is to either apply that script to an entire folder to process all images in that folder, or better yet, record a Photoshop Action that uses that script.

How can I use that script to do a batch process from either Photoshop or the Finder?

Thanks for any help for this total newbie.

Macbook Pro Core 2 Duo 17" 2.33 GHz, Mac OS X (10.4.9), More and More Disappointed in Apple Laptops

Posted on Jun 12, 2008 2:33 PM

Reply
3 replies

Jun 13, 2008 6:46 AM in response to dev_sleidy

Can do - it's below. Keeping in mind that I said I was a newbie to Applescript, I didn't include the script originally 'cause I thought there was maybe a universal way to use a script for a batch process that didn't necessarily depend on the contents of a script.

Here it is:

-- This script will crop a photo to square

tell application "Adobe Photoshop CS3"
--just be a little careful

try

set docRef to current document

on error

display dialog "must have an open document"

end try

set docWidth to width of docRef

set docHeight to height of docRef

if docWidth > docHeight then

set minDimension to docHeight

else

set minDimension to docWidth

end if

crop docRef bounds {(docWidth - minDimension) / 2, (docHeight - minDimension) / 2, (docWidth + minDimension) / 2, (docHeight + minDimension) / 2}

end tell

Jun 13, 2008 8:00 AM in response to tipperdon

The Mac I am currently using does not have 'Adobe Photoshop CS3' installed. However, based on [1], the code samples should work. Some editing may be needed, based on your specific requirements.

Sample code01:

-- Code starts here --

on run ()
my handle_Items(choose folder with multiple selections allowed)
end

on open (dItems)
my handle_Items(dItems)
end

on handle_Items(tItemss)
tell application "Adobe Photoshop CS3"

repeat with i in tItemss
set fList to list folder i without invisibles
repeat with j in fList

try
open file ((i as string) & j)

try
set docRef to current document
set (docWidth,docHeight) to (width of docRef,height of docRef)

set minDimension to docWidth
if docWidth > docHeight then set minDimension to docHeight

crop docRef bounds {(docWidth - minDimension) / 2, (docHeight - minDimension) / 2, (docWidth + minDimension) / 2, (docHeight + minDimension) / 2}

save current document
close current document saving no
end try
end try

end repeat
end repeat

end tell
end handle_Items

-- Code ends here --

Save the code as an application (AppleScript 'applet').
You and then either double click on the applet - and navigate to and select a desired folder (or folders), of which its / their contents will be processed; or, you can drag a folder (or folders) onto the applet, of which the folders contents will be processed.

-----

Code sample02:

-- Code starts here --

on adding folder items to tFolder after receiving tItems

tell application "Adobe Photoshop CS3"
repeat with i in tItems

try
open file (i as string)

try
set docRef to current document
set (docWidth,docHeight) to (width of docRef,height of docRef)

set minDimension to docWidth
if docWidth > docHeight then set minDimension to docHeight

crop docRef bounds {(docWidth - minDimension) / 2, (docHeight - minDimension) / 2, (docWidth + minDimension) / 2, (docHeight + minDimension) / 2}

save current document
close current document saving no
end try
end try

end repeat
end tell

end adding folder items to

-- Code ends here --

See ' Folder Actions Reference' about AppleScript Folder Actions; and, ' Running an automation when a folder is changed' for attaching an AppleScript Folder Action.

--- --- --- --- ---

[1] - Consult ' photoshopcs3_applescriptref.pdf' for Adobe Photoshop AppleScript classes and commands.

How to Attach Script to Photoshop Action or Folder?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.