Newbie - How can I tell Photoshop to repeat an action?

Hi -
I would like to have Photoshop open a folder with multiple images and perform an action on each image. The action is already described, and since I do not have access to Photoscripter, I will be using the “do script” command later in my script.

I’ve been trying to use the “repeat with” syntax, but I get stuck when I try to identify the folder and its contents.

Very new at this - sorry if this is really basic.

try
on open imageFolder
tell application Photoshop 7.0
do script “Analyze”
end tell
repeat with all items in imageFolder
end open
end try

Thanks for any input you might have!

-Derek

Close Derek,

Try this



set sourceFolder to "Mac HD:Desktop Folder:Some Folder:" --define the path to the folder of images

--or, if you want a user to define the folder uncomment the following
(*
set sourceFolder to choose folder with prompt "Choose your folder"--returns "alias Mac HD:Some Folder:Some Folder:"
set sourceFolder to sourceFolder as string--coerce to string so we can use it in the script below --returns "Mac HD:Some Folder:Some Folder:"
*)


tell application "Finder" to set fileList to get the name of every file of folder sourceFolder --get a listing of all files in the folder

repeat with thisFile in fileList --repeat with each file found in the folder
	set filePath to sourceFolder & thisFile as string --piece the path to the folder with the file we are on(path to the file)
	try
		tell application "Adobe® Photoshop® 5.5"
			open alias filePath --open the file we are on
			do script "Analyze"
			--hopefully your action includes a save and close step
		end tell
	end try
end repeat

Hope this helps

Thanks, Mytzlscrpt. I’ll give that a shot. I need to try to break down your script so that I can understand the logic behind it.

-Derek

Here, let me see if I can help.

set sourceFolder to "Mac HD:Desktop Folder:Some Folder:" --define the path to the folder of images 

This line sets a variable “sourceFolder” to a path to a folder. File and Folder Paths just tell your Mac where to look for something. (Sorry if that is real basic). Both File and Folder paths read from left to right and each folder is separated by a colon.

So, if I had a folder on my desktop named “Foo”, the path to this folder would be
“Mac HD:Desktop Folder:Foo:” **You can tell it’s a path to a folder if it ends with a colon.

If I had a JPEG file in that folder the path to it would be:
“Mac HD:Desktop Folder:Foo:Some File.jpg”

Any time you want to work with a file or folder you need to instruct the computer on where to find it. This is just one method.

tell application "Finder" to set fileList to get the name of every file of folder sourceFolder --get a listing of all files in the folder 

Any time you work with files or files in folders in the terms of moving, copying, getting contents of folders is a good idea to do so within a tell Finder block. You don’t have to when reading or writing files (in fact it works better if you don’t). You could also use the list folder command without involving the Finder but it would also return folder names as well. In the line above we are just getting the name of every file in our folder of files.

repeat with thisFile in fileList --repeat with each file found in the folder 

When I was first starting out the whole repeat thing confused me. There are a few different methods of using a repeat. The statement above is basically saying (repeat the following lines of code below using each of the items defined in our fileList on each pass - which is the list of file names found.) Repeat with thisFile sounds confusing but all it says is on each pass the variable thisFile will change to the next item in the list

e.g. If my folder had the following files in it:

File1
File2
File3

then it would look something like this:

1st Pass
thisFile= File1
Mac HD:Desktop Folder:Foo:File1–path to File1

2nd Pass
thisFile= File2
Mac HD:Desktop Folder:Foo:File2–path to File2

3rd Pass
thisFile = File3
Mac HD:Desktop Folder:Foo:File3–path to File3

:rolleyes: By the time you hit the repeat we already have a path to the source folder, now add the file name to the end and you have concatenated a path to a file in that folder opening up all kinds of possibilities. This is my preferred method of working with many many files in a folder. There are other ways but I think this is the fastest and least taxing on the system.

The alternate method of choosing the source folder I supplied lets the user choose a folder using a standard system dialog.

set sourceFolder to choose folder with prompt "Choose your folder"

If I navigated to that same folder I defined before, the following would be returned
alias “Mac HD:Desktop Folder:Foo:”

This next line pieces together the path to the folder and the name of the file.
Which should result in a path to a file.

set filePath to sourceFolder & thisFile as string--returns "Mac HD:Some Folder:Some Folder:whatever file we are on this pass" 

In my previous post I included a line that was redundant, not needed.

set sourceFolder to sourceFolder as string --coerce to string so we can use it in the script below --returns "Mac HD:Some Folder:Some Folder:" 

Thought I should mention that up front.

Hope this helps