Photoshop CS5: Run script on few items, 1 after the other

I don’t really know AppleScript but managed to cobble together a script that runs an action in Photoshop on some images selected in Finder.

The trouble is that when I’ve selected a few images in Finder and run the script it will often perform the Photoshop action multiple times on 1 image, rather than running the action on 1 image at a time, closing it and then running the action on the next image etc…
(The action in Photoshop crops the image to a predefined selection, saves it then closes the image, so the script shouldn’t have to).

Here’s the script I have:


tell application "Finder"
	activate
	set fileList to selection
	
	if (count result) is 0 then
		try
			get (target of front Finder window) as alias
		on error
			choose folder with prompt "Run Photoshop action on files in this folder:"
		end try
		
		try
			set fileList to every file as alias list
		end try
	end if
end tell

repeat with thisFile in fileList
	
	tell application "Finder" to open the selection using (path to application "Adobe Photoshop CS5")
	
	try
		tell application "Adobe Photoshop CS5"
			activate
			
			tell the current document
				
				do action "Crop for iPhone preview" from "Actions PS"
				
			end tell
			
		end tell
	end try
	
end repeat

Any help would be greatly appreciated.

Try this.
Replace tell application “Finder” to open the selection using (path to application “Adobe Photoshop CS5”) with.
tell app “Adobe Photoshop CS5” to open thisFile

I think the line in question is to avoid PS CS5’s problem with ‘alias’ just pass it a path as string/text. To the OP have you looked at the “Image Processor” that comes with PS? You can run actions from within that.

Thanks I tried that, but unfortunately it threw up lots of errors.

How would I pass it as string/text? (Excuse my lack of knowledge, I don’t really know AppleScript. I just cobbled together from copying and pasting parts of other scripts.)

Yes, I run quite a few actions from within Ps and Bridge, but for this instance I always find myself wanting to initiate the actions from Finder (I don’t do anything else to the images in Photoshop once I’ve run the action on them0>

Jono, this line inside of your loop opens the selected finder files in one go.

tell application "Finder" to open the selection using (path to application "Adobe Photoshop CS5")

You could do this by looping the open documents in photoshop afterwards but I would prefer to open and process one at a time. So dump that line altogether.

That way you will loop your fileList and each time a file is opened it will run the action ( I don’t have this hence the comments)

The loop with the open should go like.

repeat with thisFile in fileList
	-- try
	tell application "Adobe Photoshop CS5"
		activate
		open file (thisFile as text)
		tell the current document	
			-- do action "Crop for iPhone preview" from "Actions PS"
		end tell
	end tell
	-- end try
end repeat

That works perfectly. Thanks so much! :slight_smile: