Need a complicated Photoshop CS3 applescript

Hello there,

I’m working for a Photographer, and we need to improve our workflow.

What I’ll need is a script that open JPEG’S, erase a part of the
filenames (they have “_O3L” at the begining. ex: _O3L2148.jpg
=>2148.jpg)

Then we want the layer name to be (to follow the exemple) 2148.

Next every jpegs who are still open and who have the right names would,
all in the center of a same new document (2953x2147px 300dpi),be part of individual groups (named as the layer)
and add a text layer with the layer name to the group

I hope it’s possible and that you understood my ask

here is an exemple : http://massadian75.free.fr/macscripter/exemple.psd (for the font etc etc)
This is the exact target file, excepet it’s 50dpi and it’s suppose to be 300

Cheers

Model: MacBook Pro 15" 2.4GHz Intel Core 2 Duo/4go of Ram
AppleScript: 2.2.1
Browser: Safari 530.18
Operating System: Mac OS X (10.5)

Are you looking for a consultant to create a workflow for you or are you hoping that someone here will write it for you free of charge?

Actually I was hoping that someone will guide me…

it’s not my fisrt attempt at needing help and being ask for money,

anyway i’ll find out myself

AND MAKE A TUTORIAL THAT I WILL POST ON THE NET

BECAUSE IT SEAMS THAT SCRIPT COMMUNITY IS A BIT LOCKED UP

Actually this community is very helpful when someone is interested in learning. Your post was more like a request for a script as opposed to helping you with one though, and since you are using this professionally I think that it is reasonable that someone doing the work for you should be compensated for their time, after all that is exactly how you are making a living and this is something that will make your company more profitable and work for you less monotonous and eliminate human errors.

Feel free to write it yourself, there is a lot here that can help you. When you have some code put together and get stuck post questions here and I’m sure that they will be answered. But get rid of the ALL CAPS, there is no need for that. I believe that I asked a legitimate question, and since I have basically done everything you need done could probably have something done in a short time.

I may have badly ask my question and you understood a request of a premade script, wich is not what i want, i’m just discovering scripting and found it pretty…no REALLY USEFUL (sorry about those caplock but here they are legitimate)

I apologise for my previous, kind of stressed, post, but i’m quite short in time and your question was a bit ironical…

(btw sorry for my english)

So let’s rebiginig from start

Hello Everyone,

I’m new to the forum and to scripting and I need some advises about a script.

[i]What I want to do is a script that open JPEG’S, erase a part of the
filenames (they have “_O3L” at the begining. ex: _O3L2148.jpg
=>2148.jpg)

Then we want the layer name to be (to follow the exemple) 2148.

Next every jpegs who are still open and who have the right names would,
all in the center of a same new document (2953x2147px 300dpi),be part of individual groups (named as the layer)
and add a text layer with the layer name to the group

here is an exemple : http://massadian75.free.fr/macscripter/exemple.psd (for the font etc etc)
This is the exact target file, excepet it’s 50dpi and it’s suppose to be 300
[/i]

I don’t know where to start because this is my first script, but as i’m quite skilled informaticly i should learn quickly.

To you guys what language (is it called like that?) of scripting fits the best with my request: applescript? photoshop integrated scripts? or other?

Thanks

Mel

AppleScript: 2.2.1
Browser: Safari 530.18
Operating System: Mac OS X (10.5)

Since this is something that you want to learn the first step would be to get a book on AppleScript to get an overview of the language and download the photoshop scripting documentation as reference. This should help you get a good start on the process.

An outline that I would suggest for development purposes is creating an application which you point to a folder of files to process. From there you have the Finder give you a list of the appropriate files in the folder. Then you need to decide if you want to work on the original file or duplicate it and if you are going to leave it in the original folder or move it to a “Done” folder. If you want to use the original file then you probably want to rename it using the Finder. If you want a duplicate then you could just open the original in Photoshop and save it with the new name. Then do your photoshop stuff, save and move to the next file.

Once you have the main functions working then you might consider converting it to a drag and drop or folder action for a smoother workflow.

Hint, search the form for file rename and photoshop text, there are probably some examples on a lot of what you want to do available.

Here is the major part of your Photoshop function. I have left out a couple of things for you to learn or find here in the forum. How to trim a variable “Image_Name” to the text items you require should be very easy. and how to calculate repositioning of the text layer again basic math required. Should prove enough there to get you interested.

set Image_Folder to choose folder with prompt "Where is your folder of Images" without invisibles
--
tell application "Finder"
	set Image_List to files in Image_Folder
	set Image_Count to count of files in folder Image_Folder
end tell
-- Create new document
tell application "Adobe Photoshop CS2"
	activate
	set display dialogs to never
	set User_Rulers to ruler units of settings
	set ruler units of settings to pixel units
	set type units of settings to point units
	set Temp_Doc to make new document at beginning with properties ¬
		{mode:RGB, height:2147, width:2953, resolution:300, initial fill:transparent}
	tell Temp_Doc
		set Temp_Set to make new layer set at beginning with properties ¬
			{name:"Temp Set"}
		set Temp_Layer to make new art layer at end of Temp_Set with properties ¬
			{name:"Calque"}
		select all
		fill selection with contents {class:RGB color, red:255, green:255, blue:255}
		deselect
		set Text_Layer to make new art layer at beginning of Temp_Set with properties ¬
			{kind:text layer}
		set Text_Item to text object of Text_Layer
		set font of Text_Item to "Arial" -- Use postscript name of font here
		set size of Text_Item to 12
		set stroke color of Text_Item to {class:RGB color, red:0, green:0, blue:0}
		set position of contents of Text_Item to {25, 50}
		set contents of contents of Text_Item to "File Name"
		delete last layer -- Clear the default layer
	end tell
end tell
-- Loop through the file list
repeat with i from 1 to Image_Count
	tell application "Finder"
		set This_Image to item i of Image_Folder as alias
	end tell
	tell application "Adobe Photoshop CS2"
		tell Temp_Doc
			set Image_Set to duplicate Temp_Set to end
		end tell
		open This_Image
		set Image_Doc to the current document
		tell Image_Doc
			set Image_Name to name
			-- Trim down your file name here
			duplicate layer 1 to beginning of last layer set of Temp_Doc
			close without saving
		end tell
		tell Temp_Doc
			set name of last layer set to Image_Name
			set name of first layer of last layer set to Image_Name
			set Text_Item to text object of second art layer of last layer set
			set contents of contents of Text_Item to Image_Name
			-- Reposition your text here.
		end tell
	end tell
end repeat
-- Clean up temporary items & settings
tell application "Adobe Photoshop CS2"
	tell Temp_Doc
		delete Temp_Set
	end tell
	set ruler units of settings to User_Rulers
end tell

thank you so much Mark47, this is exactly what i was excepting,
This also helped me to understand a bit more applescript (set and tell functions for exemple)
So i have changed the Font (using the postscript name of the font) and the position.
i’ve been looking around for a while and i can’t figure out at all about removing the file extension while pasting it…
extension:false seem to be the solution but i have tried several times, to several places but it does’nt work.

if you can help me with that it would be awesome,

thanks

B.

here is my updated script:

set Image_Folder to choose folder with prompt "Choisissez dossier pour SELECT PHOTOS Horizontal" without invisibles
--
tell application "Finder"
	set Image_List to files in Image_Folder
	set Image_Count to count of files in folder Image_Folder
end tell
-- Create new document
tell application "Adobe Photoshop CS4"
	activate
	set display dialogs to never
	set User_Rulers to ruler units of settings
	set ruler units of settings to pixel units
	set type units of settings to point units
	set Temp_Doc to make new document at beginning with properties ¬
		{mode:RGB, height:2147, width:2953, resolution:300, initial fill:transparent}
	tell Temp_Doc
		set Temp_Set to make new layer set at beginning with properties ¬
			{name:"temp group"}
		set Temp_Layer to make new art layer at end of Temp_Set with properties ¬
			{name:"temp layer"}
		select all
		fill selection with contents {class:RGB color, red:255, green:255, blue:255}
		deselect
		set Text_Layer to make new art layer at beginning of Temp_Set with properties ¬
			{kind:text layer}
		set Text_Item to text object of Text_Layer
		set font of Text_Item to "HelveticaNeue-Light" -- Use postscript name of font here
		set size of Text_Item to 24
		set stroke color of Text_Item to {class:RGB color, red:0, green:0, blue:0}
		set position of contents of Text_Item to {1270, 2104}
		set contents of contents of Text_Item to "TEMP"
		delete last layer -- Clear the default layer
	end tell
end tell
-- Loop through the file list
repeat with i from 1 to Image_Count
	tell application "Finder"
		set This_Image to item i of Image_Folder as alias
	end tell
	tell application "Adobe Photoshop CS4"
		tell Temp_Doc
			set Image_Set to duplicate Temp_Set to end
		end tell
		open This_Image
		set Image_Doc to the current document
		tell Image_Doc
			set Image_Name to name
			-- Trim down your file name here
			duplicate layer 1 to beginning of last layer set of Temp_Doc
			close without saving
		end tell
		tell Temp_Doc
			set name of last layer set to Image_Name
			set name of first layer of last layer set to Image_Name
			set Text_Item to text object of second art layer of last layer set
			set contents of contents of Text_Item to Image_Name
			-- Reposition your text here.
		end tell
	end tell
end repeat
-- Clean up temporary items & settings
tell application "Adobe Photoshop CS4"
	tell Temp_Doc
		delete Temp_Set
	end tell
	set ruler units of settings to User_Rulers
end tell

In the ‘tell Image_Doc’ block you have a variable ‘Image_Name’ which has been set to the document’s name. (string)
This is just a plain old piece of text in your example “_O3L2148.jpg” (forget about extensions etc)
After that line you should be able manipulate that variable string however you wish using Applescript’s ‘text items’
Because your file naming is consistent ie the length of the text as a list of characters is always 12
You could get a list of the characters you want to use by doing this:

set Trimmed_Name to text items 5 thru 8 of Image_Name

That would return you {“2”, “1”, “4”, “8”}

But you want these back as a string of text to apply to your layers so you coerce it and use this instead:

set Trimmed_Name to text items 5 thru 8 of Image_Name as text

Now you have “2148”

In the following ‘tell Temp_Doc’ swap your variables ‘Image_Name’ in 3 places to ‘Trimmed_Name’

& Robert is your father’s brother.

Mark you where a precious help for me so the final version is:

For Landscape Photos:

set Image_Folder to choose folder with prompt "Choisissez dossier pour SELECT PHOTOS Horizontal" without invisibles
--
tell application "Finder"
	set Image_List to files in Image_Folder
	set Image_Count to count of files in folder Image_Folder
end tell
-- Create new document
tell application "Adobe Photoshop CS4"
	activate
	set display dialogs to never
	set User_Rulers to ruler units of settings
	set ruler units of settings to pixel units
	set type units of settings to point units
	set Temp_Doc to make new document at beginning with properties ¬
		{mode:RGB, height:2147, width:2953, resolution:300, initial fill:transparent}
	tell Temp_Doc
		set Temp_Set to make new layer set at beginning with properties ¬
			{name:"BJ temp"}
		set Temp_Layer to make new art layer at end of Temp_Set with properties ¬
			{name:"BJ Temp"}
		select all
		fill selection with contents {class:RGB color, red:255, green:255, blue:255}
		deselect
		set Text_Layer to make new art layer at beginning of Temp_Set with properties ¬
			{kind:text layer}
		set Text_Item to text object of Text_Layer
		set font of Text_Item to "HelveticaNeue-Light" -- Use postscript name of font here
		set size of Text_Item to 24
		set stroke color of Text_Item to {class:RGB color, red:0, green:0, blue:0}
		set position of contents of Text_Item to {1368, 2102}
		set contents of contents of Text_Item to "File Name"
		delete last layer -- Clear the default layer
	end tell
end tell
-- Loop through the file list
repeat with i from 1 to Image_Count
	tell application "Finder"
		set This_Image to item i of Image_Folder as alias
	end tell
	tell application "Adobe Photoshop CS4"
		tell Temp_Doc
			set Image_Set to duplicate Temp_Set to end
		end tell
		open This_Image
		set Image_Doc to the current document
		tell Image_Doc
			set Image_Name to name
			-- Trim down your file name here
			duplicate layer 1 to beginning of last layer set of Temp_Doc
			close without saving
		end tell
		tell Temp_Doc
			set Trimmed_Name to text items 5 thru 8 of Image_Name as text
			set name of last layer set to Trimmed_Name
			set name of first layer of last layer set to Trimmed_Name
			set Text_Item to text object of second art layer of last layer set
			set contents of contents of Text_Item to Trimmed_Name
			-- Reposition your text here.
		end tell
	end tell
end repeat
-- Clean up temporary items & settings
tell application "Adobe Photoshop CS4"
	tell Temp_Doc
		delete Temp_Set
	end tell
	set ruler units of settings to User_Rulers
end tell

and for the Portrait ones:

set Image_Folder to choose folder with prompt "Choisissez dossier pour SELECT PHOTOS Vertical" without invisibles
--
tell application "Finder"
	set Image_List to files in Image_Folder
	set Image_Count to count of files in folder Image_Folder
end tell
-- Create new document
tell application "Adobe Photoshop CS4"
	activate
	set display dialogs to never
	set User_Rulers to ruler units of settings
	set ruler units of settings to pixel units
	set type units of settings to point units
	set Temp_Doc to make new document at beginning with properties ¬
		{mode:RGB, height:2953, width:2147, resolution:300, initial fill:transparent}
	tell Temp_Doc
		set Temp_Set to make new layer set at beginning with properties ¬
			{name:"BJ temp"}
		set Temp_Layer to make new art layer at end of Temp_Set with properties ¬
			{name:"BJ Temp"}
		select all
		fill selection with contents {class:RGB color, red:255, green:255, blue:255}
		deselect
		set Text_Layer to make new art layer at beginning of Temp_Set with properties ¬
			{kind:text layer}
		set Text_Item to text object of Text_Layer
		set font of Text_Item to "HelveticaNeue-Light" -- Use postscript name of font here
		set size of Text_Item to 24
		set stroke color of Text_Item to {class:RGB color, red:0, green:0, blue:0}
		set position of contents of Text_Item to {960, 2931}
		set contents of contents of Text_Item to "File Name"
		delete last layer -- Clear the default layer
	end tell
end tell
-- Loop through the file list
repeat with i from 1 to Image_Count
	tell application "Finder"
		set This_Image to item i of Image_Folder as alias
	end tell
	tell application "Adobe Photoshop CS4"
		tell Temp_Doc
			set Image_Set to duplicate Temp_Set to end
		end tell
		open This_Image
		set Image_Doc to the current document
		tell Image_Doc
			set Image_Name to name
			-- Trim down your file name here
			duplicate layer 1 to beginning of last layer set of Temp_Doc
			close without saving
		end tell
		tell Temp_Doc
			set Trimmed_Name to text items 5 thru 8 of Image_Name as text
			set name of last layer set to Trimmed_Name
			set name of first layer of last layer set to Trimmed_Name
			set Text_Item to text object of second art layer of last layer set
			set contents of contents of Text_Item to Trimmed_Name
			-- Reposition your text here.
		end tell
	end tell
end repeat
-- Clean up temporary items & settings
tell application "Adobe Photoshop CS4"
	tell Temp_Doc
		delete Temp_Set
	end tell
	set ruler units of settings to User_Rulers
end tell

Thank you very much to everyone for helping me out!!!
You help me to finalize it and made me understand a bit more applescripts

TTTHHAANNKKSS

Here is a try about computing the 2 scripts together

need advice, “can’t get current doc of current doc” they say…

I don’t know how to put a Photoshop document in frontmost I need advice because this command will be usefull for my new script too… I’ll tell you more soon about that

Any Clue?

:|set image_folder to choose folder with prompt "Choisissez dossier pour SELECT PHOTOS Portraitical" without invisibles
tell application "Finder"
	set Image_List to files in image_folder
	set Image_Count to count of files in folder image_folder
end tell

tell application "Adobe Photoshop CS3"
	activate
	set display dialogs to never
	set User_Rulers to ruler units of settings
	set ruler units of settings to pixel units
	set type units of settings to point units
	
	set Temp_Portrait to make new document at beginning with properties ¬
		{mode:RGB, height:2953, width:2147, resolution:300, initial fill:transparent}
	
	tell Temp_Portrait
		set Temp_Set_Portrait to make new layer set at beginning with properties ¬
			{name:"BJ temp Portrait"}
		set Temp_Layer_Portrait to make new art layer at end of Temp_Set_Portrait with properties ¬
			{name:"BJ Temp Portrait"}
		select all
		fill selection with contents {class:RGB color, red:255, green:255, blue:255}
		deselect
		set Text_Layer_Portrait to make new art layer at beginning of Temp_Set_Portrait with properties ¬
			{kind:text layer}
		set Text_Item_Portrait to text object of Text_Layer_Portrait
		set font of Text_Item_Portrait to "HelveticaNeue-Light" -- Use postscript name of font here
		set size of Text_Item_Portrait to 24
		set stroke color of Text_Item_Portrait to {class:RGB color, red:0, green:0, blue:0}
		set position of contents of Text_Item_Portrait to {960, 2931}
		set contents of contents of Text_Item_Portrait to "File Name"
		delete last layer -- Clear the default layer
	end tell
end tell

tell application "Adobe Photoshop CS3"
	activate
	set Temp_Doc_Landscape to make new document at beginning with properties ¬
		{mode:RGB, height:2147, width:2953, resolution:300, initial fill:transparent}
	tell Temp_Doc_Landscape
		set Temp_Set_Landscape to make new layer set at beginning with properties ¬
			{name:"BJ temp"}
		set Temp_Layer_Landscape to make new art layer at end of Temp_Set_Landscape with properties ¬
			{name:"BJ Temp"}
		select all
		fill selection with contents {class:RGB color, red:255, green:255, blue:255}
		deselect
		set Text_Layer_Landscape to make new art layer at beginning of Temp_Set_Landscape with properties ¬
			{kind:text layer}
		set Text_Item_Landscape to text object of Text_Layer_Landscape
		set font of Text_Item_Landscape to "HelveticaNeue-Light" -- Use postscript name of font here
		set size of Text_Item_Landscape to 24
		set stroke color of Text_Item_Landscape to {class:RGB color, red:0, green:0, blue:0}
		set position of contents of Text_Item_Landscape to {1368, 2102}
		set contents of contents of Text_Item_Landscape to "File Name"
		delete last layer -- Clear the default layer
		
		
	end tell
end tell


repeat with i from 1 to Image_Count
	tell application "Finder"
		set This_Image to item i of image_folder as alias
	end tell
	tell application "Adobe Photoshop CS3"
		open This_Image
		set temp to current document
		tell temp
			if width ≤ height * 1.25 then
				tell Temp_Portrait
					set current document to Temp_Portrait
					set Image_Set_Portrait to duplicate Temp_Set_Portrait to end
				end tell
				set Image_Doc_Portrait to the last document
				tell Image_Doc_Portrait
					set Image_Name_Portrait to name
					-- Trim down your file name here
					duplicate layer 1 to beginning of last layer set of Temp_Portrait
					close without saving
				end tell
				tell Temp_Portrait
					set PortraitTrimmed_Name to (characters 1 thru -5 of Image_Name_Portrait) as string
					set name of last layer set to Trimmed_Name_Portrait
					set name of first layer of last layer set to Trimmed_Name_Portrait
					set Text_Item_Portrait to text object of second art layer of last layer set
					set contents of contents of Text_Item to Trimmed_Name_Portrait
				end tell
			else if width ≥ height * 1.25 then
				
				tell Temp_Doc_Landscape
					set Image_Set_Landscape to duplicate Temp_Set_Landscape to end
				end tell
				open This_Image
				set Image_Doc_Landscape to the last document
				tell Image_Doc_Landscape
					set Image_Name_Landscape to name
					-- Trim down your file name here
					duplicate layer 1 to beginning of last layer set of Temp_Doc_Landscape
					close without saving
				end tell
				tell Temp_Doc_Landscape
					set LandscapeTrimmed_Name to (characters 1 thru -5 of Image_Name_Landscape) as string
					set name of last layer set to Trimmed_Name_Landscape
					set name of first layer of last layer set to Trimmed_Name_Landscape
					set Text_Item_Landscape to text object of second art layer of last layer set
					set contents of contents of Text_Item_Landscape to Trimmed_Name_Landscape
				end tell
			end if
			
		end tell
	end tell
end repeat

Rather than setting about with lots of duplicated code why not look at creating some sub-routines that you can pass a couple of variables to and call those to handle much of the process. In this example which opens the first file of your list then checks to see if its landscape or portrait then calls a sub to make the template file dupes the first over then loops from the second file in the list duping over and so on.

Also when using ≤ ≥ with your if else conditions include the equal on only one side or it could equate to both

set Image_Folder to choose folder with prompt "Where is your folder of Images" without invisibles
--
tell application "Finder"
	set Image_List to files in Image_Folder
	set Image_Count to count of files in folder Image_Folder
	set This_Image to item 1 of Image_Folder as alias
end tell
-- Create new document
tell application "Adobe Photoshop CS2"
	activate
	set display dialogs to never
	set User_Rulers to ruler units of settings
	set ruler units of settings to pixel units
	set type units of settings to point units
	open This_Image
	set Image_Doc to the current document
	tell Image_Doc
		set {Doc_height, Doc_Width} to {height, width}
	end tell
end tell
-- Create new document then dupe the already open Image_Doc
if Doc_height ≥ Doc_Width then
	set {Temp_Doc, Temp_Set} to Make_Temp(2953, 2147, {960, 2931}) -- Portrait or Square
	Dupe_Layer(Image_Doc, false, Temp_Doc, Temp_Set) -- Passing Image_Doc
else
	set {Temp_Doc, Temp_Set} to Make_Temp(2147, 2953, {1368, 2102}) -- Landscape
	Dupe_Layer(Image_Doc, false, Temp_Doc, Temp_Set) -- Passing Image_Doc
end if
-- Loop through the file list from the second file
repeat with i from 2 to Image_Count
	tell application "Finder"
		set This_Image to item i of Image_Folder as alias
	end tell
	my Dupe_Layer(false, This_Image, Temp_Doc, Temp_Set) -- Passing This_Image
end repeat
-- Clean up temporary items & settings
tell application "Adobe Photoshop CS2"
	tell Temp_Doc
		delete Temp_Set
	end tell
	set ruler units of settings to User_Rulers
end tell
-- Make template document using 3 parameters
on Make_Temp(Doc_height, Doc_Width, Text_Position)
	tell application "Adobe Photoshop CS2"
		set Temp_Doc to make new document at beginning with properties ¬
			{mode:RGB, height:Doc_height, width:Doc_Width, resolution:300, initial fill:transparent}
		tell Temp_Doc
			set Temp_Set to make new layer set at beginning with properties ¬
				{name:"Temp Set"}
			set Temp_Layer to make new art layer at end of Temp_Set with properties ¬
				{name:"Calque"}
			select all
			fill selection with contents {class:RGB color, red:255, green:255, blue:255}
			deselect
			set Text_Layer to make new art layer at beginning of Temp_Set with properties ¬
				{kind:text layer}
			set Text_Item to text object of Text_Layer
			set font of Text_Item to "Arial" -- Use postscript name of font here
			set size of Text_Item to 12
			set stroke color of Text_Item to {class:RGB color, red:0, green:0, blue:0}
			set position of contents of Text_Item to Text_Position
			set contents of contents of Text_Item to "File Name"
			delete last layer -- Clear the default layer
		end tell
	end tell
	return {Temp_Doc, Temp_Set}
end Make_Temp
-- Dupe layer from either Image_Doc or This_Image
on Dupe_Layer(Image_Doc, This_Image, Temp_Doc, Temp_Set)
	tell application "Adobe Photoshop CS2"
		tell Temp_Doc
			set Image_Set to duplicate Temp_Set to end
		end tell
		if This_Image is not false then -- Open file optional
			open This_Image
			set Image_Doc to the current document
		end if
		set the current document to Image_Doc
		tell Image_Doc
			set Image_Name to name
			set Trimmed_Name to text items 5 thru 8 of Image_Name as text
			duplicate layer 1 to beginning of last layer set of Temp_Doc
			close without saving
		end tell
		tell Temp_Doc
			set name of last layer set to Trimmed_Name
			set name of first layer of last layer set to Trimmed_Name
			set Text_Item to text object of second art layer of last layer set
			set contents of contents of Text_Item to Trimmed_Name
		end tell
	end tell
end Dupe_Layer

This is almost that except
I wished images of my folder (contaigning Landscape and Square) would be recognise and that if i’m opening my script,

he detects which are landscapes and which are Squares and if both are present he creates Two different document (One Portrait (Vertical) and one Landscape (Horizontal))

Please Help
Thanks

B.