Help!! Opening all sequential files in a folder with PS

The Problem

Hi guys and Gals! I’m trying :rolleyes: to modify Cristos excellent script so it opens all the files in a folder sequentially (they are numerical named 1 thru to 14) then processes them with the Photoshop action and then saves them to the predetermined folder. Before moving on to process the next folder.

Anyone got any ideas?

--This AS is made by Christopher Wiedswang, cristo@online.no. It´s put together with bits and pieces found around...
set deliMiter to AppleScript's text item delimiters
property dialog_timeout : 30 -- set the amount of time before dialogs auto-answer.
set alert_message to "Select folder to process:"

display dialog the alert_message buttons {"Cancel", "OK"} default button 2 with icon 1 giving up after dialog_timeout
set inputFolder to choose folder

set alert_message to "Select folder to save processed folders in:"

display dialog the alert_message buttons {"Cancel", "OK"} default button 2 with icon 1 giving up after dialog_timeout
set outputFolder to choose folder

tell application "Finder"
	set folderList to folders in inputFolder
end tell

repeat with aFolder in folderList
	set AppleScript's text item delimiters to ""
	set toThis to aFolder as string
	if the toThis ends with ":" then
		set the toThru to ((the number of characters of the toThis) - 1)
		set toThis to (characters 1 thru toThru of toThis) as string
	end if
	if the toThis contains ":" then
		set AppleScript's text item delimiters to {":"}
		set toThis to get last text item of toThis
		set AppleScript's text item delimiters to deliMiter
	end if
	
	tell application "Finder"
		set filesList to files in aFolder
		if (not (exists folder ((outputFolder as string) & toThis))) then
			set suboutputFolder to make new folder at outputFolder with properties {name:toThis}
		else
			set outputFolder to folder ((outputFolder as string) & toThis)
		end if
	end tell
	
	tell application "Adobe Photoshop 7.0"
		set display dialogs to never
		close every document saving yes
	end tell
	
	repeat with aFile in filesList
		
		
		tell application "Finder"
			-- The step below is important because the 'aFile' reference as returned by
			-- Finder associates the file with Finder and not Photoshop. By converting
			-- the reference below 'as alias', the reference used by 'open' will be
			-- correctly handled by Photoshop rather than Finder.
			set theFile to aFile as alias
			set theFileName to name of theFile
		end tell
		
		
		tell application "Adobe Photoshop 7.0"
			
			set startRulerUnits to ruler units of settings
			set ruler units of settings to pixel units
			open theFile
			set docRef to current document
			
			--Her goes your actions, you have to change "imageSizeB" and "Applescript" with your action name("imageSizeB") and from folder set("Applescript")
			
			do action "Sepia Toning (layer)" from "Default Actions"
			
			
			
			-- Convert the document to a document mode that supports saving as jpeg
			if (bits per channel of docRef is sixteen) then
				set bits per channel of docRef to eight
			end if
			
			set docName to name of docRef
			set docBaseName to getBaseName(docName) of me
			set newFileName to (suboutputFolder as string) & docBaseName
			
			-- This is the saving properties, which saves as JPEG, quality 12
			set myOptionsJPG to ¬
				{class:JPEG save options, embed color profile:true, format options:standard, matte:none, quality:12}
			save docRef in file newFileName as JPEG with options myOptionsJPG appending lowercase extension with copying
			
			close current document without saving
			
		end tell
	end repeat
end repeat





set the date_stamp to ((the current date) as string)

set alert_message to "The job is done at " & date_stamp & ", I´m waiting for more..." as Unicode text

display dialog the alert_message buttons {"Show me", "No thanks"} default button 2 with icon 1 giving up after dialog_timeout
set the user_choice to the button returned of the result

if user_choice is "Show me" then
	tell application "Finder"
		--go to the desktop 
		activate
		--open the folder
		open outputFolder
	end tell
end if




-- Returns the document name without extension (if present)
on getBaseName(fName)
	set baseName to fName
	repeat with idx from 1 to (length of fName)
		if (item idx of fName = ".") then
			set baseName to (items 1 thru (idx - 1) of fName) as string
			exit repeat
		end if
	end repeat
	return baseName
end getBaseName

Cheers for taking the time to help me.

TimP

Model: G4 733 Quicksilver
AppleScript: 1.9.3
Browser: Safari 312
Operating System: Mac OS X (10.3.9)

This looks like it processes files located in subfolders of the selected folder. Will you have subfolders to consider, or do you just want to process files located in the selected folder?

Hi Digest4d,

Thanks for the post,

Yeah your right, what I really want is to sequentially open all the files (named 1.jpg thur to 14.jpg) contained within one of the sub folders in Photoshop. The action would then process the open images, save them in the new folder/location and finally close them.

The whole process would then repeat on the files conatined within the next subfolder, and so on and so on, until all the subfolders contained within the master folder had been processed.

Cristo’s, brilliant script does everything that I want but it process’s each file individually, the action which I intend to use needs all the files contained within each subfolder open in a order. (either acsending or desending numerical order).

I hope this clears up the process.

Thanks for taking the time to try and help me.

Cheers

Tim P:)

Model: G4 733 Quicksilver
AppleScript: 1.9.3
Browser: Safari 312
Operating System: Mac OS X (10.3.9)

I think your saying you need all the photos in a subfolder open at once, do actions, then the next subfolder of photos open all at once, etc…


set mastFold to (choose folder) -- The master folder with the subfolders

tell application "Finder"
	set YourSubs to items of mastFold --The subfolders as a list
end tell

repeat with thisSub in YourSubs --Grabs a subfolder one at a time
	tell application "Finder"
		set filelist to items of thisSub --Photos in subfolder become filelist
	end tell
	
	repeat with thepic in filelist --Grabs a pic one at a time from individual subfolder
		open thepic
	end repeat
	
	display dialog "You can do your actions here"--Remove this dialog and add the photoshop actions here, probably ending with "close all open windows"
	
end repeat

SC

Hi Sitcom,

Thanks for the post,

When I tried your script, all the images opened in Preview and not Photoshop. Also all the images opened from all of the subfolders contained within the master folder :confused: Am I doing something wrong?

set mastFold to (choose folder) -- The master folder with the subfolders

tell application "Finder"
	set YourSubs to items of mastFold --The subfolders as a list
end tell

repeat with thisSub in YourSubs --Grabs a subfolder one at a time
	tell application "Finder"
		set filelist to items of thisSub --Photos in subfolder become filelist
	end tell
	
	repeat with thepic in filelist --Grabs a pic one at a time from individual subfolder
		open thepic
	end repeat
	
	tell application "Adobe Photoshop 7.0"
		do action "Sepia Toning (layer)" from "Default Actions"
	end tell
	
end repeat

Thanks for taking the time to try and help me.

Cheers

Tim P :slight_smile:

Model: G4 733 Quicksilver
AppleScript: 1.9.3
Browser: Safari 312
Operating System: Mac OS X (10.3.9)

ArrrrrrrrrrrrrG! I am very sorry… The photos I was testing were Photoshop pics and open in Photoshop automatically.


set mastFold to (choose folder) -- The master folder with the subfolders

tell application "Finder"
   set YourSubs to items of mastFold --The subfolders as a list
end tell

repeat with thisSub in YourSubs --Grabs a subfolder one at a time
   tell application "Finder"
       set filelist to items of thisSub --Photos in subfolder become filelist
   end tell
   
   repeat with thepic in filelist --Grabs a pic one at a time from individual subfolder
     tell application "Adobe Photoshop 7.0"--This sets PS to open the pics inside repeat  
         open thepic
     end tell
end repeat

--This is inside of the 'repeat with subfolder' rountine. Here you will have a subfolder of opened pictures waiting on commands. Whatever is entered here will act, then when completed see the following "end repeat" statement and go on to the next subfolder.
   
   display dialog "You can do your actions here"--Remove this dialog and add the photoshop actions here, probably ending with "close all open windows"
   
end repeat


The way that script works, all the pics in one subfolder open at once. The dialog that comes up stops the opening of pics at the end of each folder as an example of actions that would take place in that section of code. Notice when you click “ok” on the dialog box the next folder of pics open. If you just keep clicking “ok” all the pics open.

I did this in response to your request:

Cristo’s script does everything I want but it process’s each file individually, the action which I intend to use needs all the files contained within each subfolder open in a order.
In my view, this script does just that: opens “all the files contained within each subfolder open in a order” Then the dialog comes up. Nothing else will happen until you click “ok”, which represents the computer working on your images until it opens the next subfolder.
Did I misunderstand?

I think we need a forum syntax for explaining scripts we want-:lol:
SC

Hey Sitcom,

:lol: I’m with you about needing a forum syntax for explaining scripts we want! (but knowing me I still wouldnt be able to explain myself! :rolleyes:)

As for understanding my friend you spot on! Your script is excellent and is just what I’m trying to accomplish.

I’m just having two problems, firstly Preview is still opening when I run the script (ArrrrrrrrrrrrrG!) could it be that the files are associated with Preview and automatically open the progeame? I then want to in insert your script into Cristo’s Script? (I can feel myself digging a big deep hole here!)

Am I making sense? (I feel like I’m mentally dribbling here)

Thanks for taking the time to try and help me.

Cheers

Tim P :slight_smile:

Model: G4 733 Quicksilver
AppleScript: 1.9.3
Browser: Safari 312
Operating System: Mac OS X (10.3.9)

I was able to repeat Preview opening as well. The author made a note here about the problem:


 tell application "Finder"
           -- The step below is important because the 'aFile' reference as returned by
           -- Finder associates the file with Finder and not Photoshop. By converting
           -- the reference below 'as alias', the reference used by 'open' will be
           -- correctly handled by Photoshop rather than Finder.
           set theFile to aFile as alias
           set theFileName to name of theFile
       end tell

New Version:


set mastFold to (choose folder) -- The master folder with the subfolders

tell application "Finder"
	set YourSubs to items of mastFold --The subfolders as a list
end tell

repeat with thisSub in YourSubs --Grabs a subfolder one at a time
	tell application "Finder"
		set filelist to items of thisSub --Photos in subfolder become filelist
	end tell
	
	repeat with thePic in filelist --Grabs a pic one at a time from individual subfolder
		tell application "Finder"
			-- The step below is important because the 'aFile' reference as returned by
			-- Finder associates the file with Finder and not Photoshop. By converting
			-- the reference below 'as alias', the reference used by 'open' will be
			-- correctly handled by Photoshop rather than Finder.
			set TheFile to thePic as alias
			
		end tell
		
		tell application "Adobe® Photoshop 7" --This sets PS to open the pics inside repeat  
			open TheFile
		end tell
	end repeat
--Insert Photoshop actions here
display dialog "Insert Photoshop actions here"

end repeat

It is more accurate to say you will insert portions of Cristo’s Script into ^Your Script^ in place of the display dialog. Cristo’s script says what to do, but the new script tells when to do it. So it may take a bit of debugging; Emailing the author with what you’re trying to achieve and what you’ve got so far might help.
I’ll work on this and get back
SC

Hi Sitcom,

Sorry I have not been able to answer for the last week but real world work has stopped me bing able to work on this problem! :frowning:

As always thanks for all the help but I could not seem to get the last script that you suggested to work. :frowning: I’m probably doing something wrong, but when I try to compile the code I just get the dreaded beach ball of death!

I have even tried inserting it into Cristo’s code but that again just causes the system to freeze up!


--This AS is made by Christopher Wiedswang, cristo@online.no. It´s put together with bits and pieces found around...
set deliMiter to AppleScript's text item delimiters
property dialog_timeout : 30 -- set the amount of time before dialogs auto-answer.
set alert_message to "Select folder to process:"


set mastFold to (choose folder) -- The master folder with the subfolders

tell application "Finder"
	set YourSubs to items of mastFold --The subfolders as a list
end tell

repeat with thisSub in YourSubs --Grabs a subfolder one at a time
	tell application "Finder"
		set filelist to items of thisSub --Photos in subfolder become filelist
	end tell
	
	repeat with thePic in filelist --Grabs a pic one at a time from individual subfolder
		tell application "Finder"
			-- The step below is important because the 'aFile' reference as returned by
			-- Finder associates the file with Finder and not Photoshop. By converting
			-- the reference below 'as alias', the reference used by 'open' will be
			-- correctly handled by Photoshop rather than Finder.
			set TheFile to thePic as alias
			
		end tell
		
		tell application "Adobe® Photoshop 7" --This sets PS to open the pics inside repeat  
			open TheFile
		end tell
	end repeat
--Insert Photoshop actions here
display dialog "Insert Photoshop actions here"

end repeat


set alert_message to "Select folder to save processed folders in:"

display dialog the alert_message buttons {"Cancel", "OK"} default button 2 with icon 1 giving up after dialog_timeout
set outputFolder to choose folder

tell application "Finder"
	set folderList to folders in inputFolder
end tell

repeat with aFolder in folderList
	set AppleScript's text item delimiters to ""
	set toThis to aFolder as string
	if the toThis ends with ":" then
		set the toThru to ((the number of characters of the toThis) - 1)
		set toThis to (characters 1 thru toThru of toThis) as string
	end if
	if the toThis contains ":" then
		set AppleScript's text item delimiters to {":"}
		set toThis to get last text item of toThis
		set AppleScript's text item delimiters to deliMiter
	end if
	
	tell application "Finder"
		set filesList to files in aFolder
		if (not (exists folder ((outputFolder as string) & toThis))) then
			set suboutputFolder to make new folder at outputFolder with properties {name:toThis}
		else
			set outputFolder to folder ((outputFolder as string) & toThis)
		end if
	end tell
	
	tell application "Adobe Photoshop 7.0"
		set display dialogs to never
		close every document saving yes
	end tell
	
	repeat with aFile in filesList
		
		
		tell application "Finder"
			-- The step below is important because the 'aFile' reference as returned by
			-- Finder associates the file with Finder and not Photoshop. By converting
			-- the reference below 'as alias', the reference used by 'open' will be
			-- correctly handled by Photoshop rather than Finder.
			set theFile to aFile as alias
			set theFileName to name of theFile
		end tell
		
		
		tell application "Adobe Photoshop 7.0"
			
			set startRulerUnits to ruler units of settings
			set ruler units of settings to pixel units
			open theFile
			set docRef to current document
			
			--Her goes your actions, you have to change "imageSizeB" and "Applescript" with your action name("imageSizeB") and from folder set("Applescript")
			
			do action "Sepia Toning (layer)" from "Default Actions"
			
			
			
			-- Convert the document to a document mode that supports saving as jpeg
			if (bits per channel of docRef is sixteen) then
				set bits per channel of docRef to eight
			end if
			
			set docName to name of docRef
			set docBaseName to getBaseName(docName) of me
			set newFileName to (suboutputFolder as string) & docBaseName
			
			-- This is the saving properties, which saves as JPEG, quality 12
			set myOptionsJPG to ¬
				{class:JPEG save options, embed color profile:true, format options:standard, matte:none, quality:12}
			save docRef in file newFileName as JPEG with options myOptionsJPG appending lowercase extension with copying
			
			close current document without saving
			
		end tell
	end repeat
end repeat





set the date_stamp to ((the current date) as string)

set alert_message to "The job is done at " & date_stamp & ", I´m waiting for more..." as Unicode text

display dialog the alert_message buttons {"Show me", "No thanks"} default button 2 with icon 1 giving up after dialog_timeout
set the user_choice to the button returned of the result

if user_choice is "Show me" then
	tell application "Finder"
		--go to the desktop 
		activate
		--open the folder
		open outputFolder
	end tell
end if




-- Returns the document name without extension (if present)
on getBaseName(fName)
	set baseName to fName
	repeat with idx from 1 to (length of fName)
		if (item idx of fName = ".") then
			set baseName to (items 1 thru (idx - 1) of fName) as string
			exit repeat
		end if
	end repeat
	return baseName
end getBaseName

Is this what you ment by replacing the display dialog??? option or should I just be able to run your script independently??



set mastFold to (choose folder) -- The master folder with the subfolders

tell application "Finder"
	set YourSubs to items of mastFold --The subfolders as a list
end tell

repeat with thisSub in YourSubs --Grabs a subfolder one at a time
	tell application "Finder"
		set filelist to items of thisSub --Photos in subfolder become filelist
	end tell
	
	repeat with thePic in filelist --Grabs a pic one at a time from individual subfolder
		tell application "Finder"
			-- The step below is important because the 'aFile' reference as returned by
			-- Finder associates the file with Finder and not Photoshop. By converting
			-- the reference below 'as alias', the reference used by 'open' will be
			-- correctly handled by Photoshop rather than Finder.
			set TheFile to thePic as alias
			
		end tell
		
		tell application "Adobe® Photoshop 7" --This sets PS to open the pics inside repeat  
			open TheFile
		end tell
	end repeat
--Insert Photoshop actions here
display dialog "Insert Photoshop actions here"

end repeat


Am I making sense? (I feel like I’m mentally dribbling here)

Thanks for taking the time to try and help me.

Cheers

Tim P :rolleyes:

Model: G4 733 Quicksilver
AppleScript: 1.9.3
Browser: Safari 312
Operating System: Mac OS X (10.3.9)

Lets take a moment to breathe…
OK enough of that-

Which brings to mind a comment from Kel, “Wishful thinking will get you nowhere”. That’s not being mean, its being truthful. From that statement I can tell that you don’t have a firm grasp of what your doing, which is OK. You just need to take some time to understand exactly what’s going on.

Cristo’s “photoshop actions” are targeted at a single file, one by one in a folder.


ll application "Finder"
   set folderList to folders in inputFolder--Everything that follows is getting the files
end tell

repeat with aFolder in folderList
--His script lines
   end if
   
   tell application "Finder"
       set filesList to files in aFolder--filesList is a list of the photos

Then he gets the individual files


repeat with aFile in filesList--This grabs a photo, one at a time, and processes it

All of his photoshop actions come here. This is where your script is utterly different and will never allow a cut and paste to complete the script. Why?

He opens a file at a time, referred to as ‘aFile’ in filesList. AS looks for this item, and executes code on it.

You changed the game by opening all pics at once, and then wanting to execute code on all of them. You will have to make code that tells Photoshop which items to go to work on.

so I gave you the code


set mastFold to (choose folder) -- The master folder with the subfolders

tell application "Finder"
   set YourSubs to items of mastFold --The subfolders as a list
end tell

repeat with thisSub in YourSubs --Grabs a subfolder one at a time
   tell application "Finder"
       set filelist to items of thisSub --Photos in subfolder become filelist
   end tell
   
   repeat with thePic in filelist --Grabs a pic one at a time from individual subfolder
       tell application "Finder"
           -- The step below is important because the 'aFile' reference as returned by
           -- Finder associates the file with Finder and not Photoshop. By converting
           -- the reference below 'as alias', the reference used by 'open' will be
           -- correctly handled by Photoshop rather than Finder.
           set TheFile to thePic as alias
           
       end tell
       
       tell application "Adobe® Photoshop 7" --This sets PS to open the pics inside rep   
           open TheFile
       end tell
end repeat

--This is the place in the code where you have your pictures all open. You can't just paste Cristo's code here because it's more than just Photoshop actions. You have to tell AS what and where!!! And he has dialog references at the beginning that are used later. This all needs to be reassembled. I don't understand why you need all open at once, so this is where I have a weak foundation for going any further.

--tell application "Adobe® Photoshop 7"
--repeat with thePic in filelist--This might work, acting on each one while they're open
--OR 
--set WinNum to count windows ??? 
--repeat with  WinNum in windows ??? Here you try to target the pics as the open windows
--Now attempt to execute code (only the code that is relevant!!!) on all the open windows, key word attempting.
--end repeat
--end tell

end repeat


What I need to know is, why do all pics in the folder need to be open at once? What action occurs through this parameter that isn’t done when processed one at a time?
**This is detailed stuff. I would highly recommend contacting the author of the original and letting them know what you are attempting.
SC

Hi Sitcom,

Yeah I think you have hit the nail on the head, I just don’t have the abilities and understanding to create the script that I want and what I need.

Basically the problem is I have several sub folders contained with in a main folder. Each sub folder contains a number of .JPGs that are labelled numerically from 01 onwards.

For each sub folder I want to create a calendar of images, with the first file 01.JPG being used for the month of January and 12.JPG being used for the month of December.

This is why I need all the images open numerically in Photoshop, So that I can create a Photoshop action that takes the first image and places it on the corresponding month on a premade template.

After the Photoshop action has correctly created all the calendar pages, they are then saved as the highest quality JPEG in a new folder (which is named after the sub folder where the images were originally opened)

As you already know Cristo’s script does exactly this, but it processes each file individually. The great script, which you made, opens all the files in a particular folder. I’m sure I can produce the relevant action script to place the images (when opened) on the correct month of the calendar template, but any of the action scripting is where I’m having problems.

The script would then process the next sub folder from the main folder creating a separate calendar for each sub folder.

Does all this make sense? I have tried getting in contact with Cristo but he never replies. I will try again.

Can you help me with the action script?

Thanks for taking the time to try and help me.

My email address is timpruce@hotmail.com

Cheers

Tim P

Model: G4 733 Quicksilver
AppleScript: 1.9.3
Browser: Safari 312
Operating System: Mac OS X (10.3.9)

:expressionless:
That look is for me, not you :lol:

My apologies for not asking this in the beginning. This has been recently posted as a sticky for newbs:

A couple of people in here responded to a post to cross reference numbered jpegs to the months. Was that you? If not, someone is doing a similar task. You don’t HAVE to open all the jpegs at once to achieve your goal. Oh so important to state the goal before running around trying to find a means.
To associate the jpgs to a premade template, you can make a list.

set MonthList to {“January”, “February”,…}–These should be your template names

then you would get the number of the jpg picture as they came, 01.jpg can be stripped to “1”. Then you would send the jpg to item “1” in the list, “January”, on so on. That’s not the final word on it, just a thought.

You may just have a custom sort issue. In other words, your saying the pics don’t open in the right order? If we could sort the fileLIst so that they were processed 1,2,3,4, etc would that solve the problem?And most importantly -kick me for not asking earlier-
Does Christo’s script work for you now, only thing wrong is the order it grabs the jpgs???
SC

Hi Sitcom,

As Usal thanks for thaking the time to replie.

Im sorry im totally lost maybe I should say more!

The teplate is a photoshop document where each layer is a seperate month.

Yes basically Christos script does everything that i want, it processes all the sub folder with in the original images folder it creates new folders in the processed folder named after the original sub folder, it saves all the images to the correct location at the highest JPG quality. It does all these things automated without having to hover over the computer clicking dialog boxes.

The only problem is that it opens each image 1 by 1 within each sub folder. For my action to work, I imagined all the images within one folder to be opened at once in a sequencal order, the template would then be opened. Image 01.jpg would be then moved to the jan layer on the template 02.jpg would be moved to the feb layer etc etc and then each month would be saved as a JPG in the right place within the processed folder.

Does this make things any clearer? I hope so, please if I can explain myself more or you want any more clarification do not hesitate to email me back!

Once again thank you for taking the time to help me.

Cheers

Tim P

Model: G4 733 Quicksilver
AppleScript: 1.9.3
Browser: Safari 312
Operating System: Mac OS X (10.3.9)

The problem is I originally responded to your post

Because I had high confidence that I could fix the order the files opened as requested in the post. We did that, and that’s when it came to light that you needed a bit more than that :lol: . So… The goal is the method, as always, so let’s check further into that.
Once you’ve created this calendar set, what are you going to do with it? edit Since you are going to print it, JPEG is the wrong format to save in, as well as other factors. So before you save everything to JPEG, define what your doing with the result. Images for high-gloss prints used in calendars should be saved at 300 dpi (absolute min 150), CMYK color, TIFF image.
I put a post in here asking if anyone could script photoshop to set a transparent text image over a photo, and no response
. Then I noticed almost every photoshop post had no successful replies, only suggestions of info links. I don’t get it- I thought that merging two images would be one of the most essential and common photoshop scripts. Thanks Adobe :expressionless:

*ktam responded to my post letting me know about a freeware program he made called ‘iMagine’ photo, and said it “can blend images together, and take into account transparency information” using scripting. Here is the post and the program:
http://bbs.applescript.net/viewtopic.php?id=12789
I think he could help you make a script to do your tasks (actually he said he has one that’s more that what you need); I recommend doing the pattern of Christo’s script. ie, open a jpg, open a template, merge, save, repeat w/ next image. It’s cleaner, and easier to script since you only work on one at a time.
Think about this- if you burn 1000 gallons of gasoline running the machinery to pump enough oil from the ground to make 800 gallons of gasoline, what have you just done?
SC
Thanks for the help ktam