Create Photoshop Actions

Hi,

I have a script that colours up spot colour channels in Photoshop, depending on the colour name in the filename. It does this by invoking an action that defines the current channel’s name and CMYK breakdown.
I have a small number of actions (one per colour), but now my other script is working, I need to create an action for each of the 1000 colours in the library. I have the library saved as an excel file with the CMYK breakdowns in separate cells.
Does anyone have experience of this, or any ideas for going about this. It seems scriptable, but seems pretty daunting to me.

Any help you could give would be much appreciated.

Ian

As long as what you need to do is Applescriptable in Photoshop, you really don’t need to use actions (although they do run faster in my experience). There may be a better way of doing this (with records instead of the if/then conditional), but here’s how I would approach it:

First thing would be to define a step by step play of what you need:

1)Get file name
2)

If file name is (X) then
do (whatever your action is doing) with these (values from worksheet for X)
else if file name is (Y) then
do (whatever your action is doing) with these (values from worksheet for Y) 
--and so on
end if

Which is pretty basic. Once you have the AS figured out for what you need to do in Photoshop, I would then save all the data in the excel file as a tab-delimited file because it would be MUCH easier to work with.

As far as writing the actual applescript (1000 entries by hand???), I would set up a repeat loop to read the values and plug them into a variable string.

If you need more reference, try searching for “reading a file” “writing to file” “conditionals” and “repeat loops”. For the Photoshop part, check out the Scripting samples and guides that came with Photoshop.

-N

Ian, im not sure what it is that you are trying to do. Do you want script to create new actions from database info? if this is the case then I don’t think script can create actions to my knowledge it can only do action. What is your goal with these spot colour images and can you show the other script to give a better idea.

Thanks for your replies,

When we have artwork that has transparency (drop shadows, glows etc) in it, we have a workflow that flattens the file and spits out a 8-bit tif for each separation (a bit like a RIP). We then recombine these greyscale tifs back into one composite DCS2 file, which is put back into the artwork. At the moment, it is done manually. The spot colour channels are name and coloured up according the CMYK breakdown with a PS action.
The script for this side of things works well (not thoroughly tested, but I’m getting there)

--set counters for repeat and set up empty list to add to
set x to 1
set y to 1
set chnnl_list to {}
--choose folder of images
set Image_folder to choose folder with prompt "Please choose folder of images"

tell application "Finder"
	set all_images to every item in Image_folder as alias list
	get displayed name of item 1 of all_images
	--get Job number for saving later
	set job1 to the result
	get characters 1 thru 6 of job1
	set job_num to the result as string
	set numChannels to the (count of items in all_images) as number
	--extract the XX name from the file name and add to list
	repeat with n from 1 to numChannels
		get characters -5 thru -11 of (displayed name of item x of all_images as string) as text
		set chnnl to the result as list
		set end of chnnl_list to chnnl
		set x to x + 1
	end repeat
end tell

--duplicate the first file to use as master image : all images will be added to this (correct for size)
tell application "Finder"
	try
		set dup_image to duplicate item 1 of Image_folder
		move dup_image to desktop with replacing
		set master_image to the result as alias
	end try
end tell

tell application "Adobe Photoshop CS2"
	open master_image
	activate
	tell front document
		change mode to multichannel
		select all
		clear
		--create channels and colour them from XX colour Action set
		repeat numChannels times
			set chnnl_name to item y of chnnl_list
			try
				do action (chnnl_name as text) from "XX COLOURS"
			on error
				display dialog "XX Colour not in Action Set" buttons {"Continue"} default button "Continue"
			end try
			open item y of all_images
			--add information into channel from separate files
			tell application "Adobe Photoshop CS2"
				tell document 2
					select all
					copy
					close
					paste
				end tell
			end tell
			make new channel with properties {opacity:0.0}
			set y to y + 1
		end repeat
		--there is always an extra channel, so needs to be deleted
		delete channel (numChannels + 1)
		deselect
	end tell
end tell

As you can see from the script, it does a ‘do action’ from the colour action set. I have a small number of actions to test, but in order for it to work successfully with most colours it comes across, I would like a separate script that takes the names and values from an excel worksheet (or csv) and creates an action for each (set current channel > name > CYMK colour) in Photoshop. I haven’t come across much information in the PS scripting guide, although it hints that this may be possible in Javascript (which is then run with an Applescript).

I may have bitten off more than I can chew, but I don’t fancy creating 1000 actions one at a time!

Thanks

Ian

PS. The first script doesn’t work with 1 image. Why can a list contain 0 or 2 or more items, but not 1? Strange :confused:

Ian, this should catch the error of 1 item as alias list. While I take a look at the other stuff. I take it your artwork is created in Quark if you are using composite DCS2. I dropped this years ago so I could have composite PDF workflow. Are you using DCS merger to get around this or just working in pre-separated enviroment?

tell application "Finder"
	try
		set all_images to every item in Image_folder as alias list
	on error -- only one file
		set all_images to every item in Image_folder as alias as list
	end try
end tell

Mark,
Thanks, I’ll drop that script into the beginning of my script.

We are using Illustrator and ArtPro. We use an Illustrator plug-in called Esko Backstage to deal with DCS and transparency normally. It is only when the jobs have to go to printers in a specific format that we resort to creating flattened files. We have experimented with PSDs and PDFs, but we have come across problems and compatibilty issues.

Ian

Is what you are doing with the Action not possible with Applescript?

Can you post a sample action?

-N

Have a look at:
http://uk.geocities.com/i.mcpherson@btinternet.com/XX_COLOURS.atn.sit

It seemed to be easier to reference an existing list (of actions) from within Photoshop during the course of the original script.
If there is a way to pass the excel information directly to the channel during the script, then that would help me lots.

Thanks for all your ideas and interest.

Ian

Ian,

DL’ed your actions, and unless I’m missing something fundamental you can replace them with something simple when creating the channel:



set color_name to "XX 001"

	if color_name is "XX 001" then
		set color_name to color_name
		set C to 0
		set M to 79
		set Y to 94
		set K to 0
	else if color_name is "XX 002" then
		set color_name to color_name
		set C to 100
		set M to 9
		set Y to 0
		set K to 6
		----and so on
	end if



tell application "Adobe Photoshop CS"
	activate
	make new channel at current document with properties {name:color_name, kind:spot color channel, channel color:{class:CMYK color, cyan:C, magenta:M, yellow:Y, black:K}}
	end tell

I created 500 “conditonals” (which is easily done using tab-delimited data as I mentioned earlier) and it took about a second to execute on a PB 1.5ghz. You may have to dial in the channel properties, but this should get you going.

-N

nedloh99,

Thanks for your example, but I’m a bit lost now.
Would there be a list of values at the top of my script, with all of the 1000 values in it, and if so, how is this accomplished with a comma separated file? Or do you reference the csv file externally?

Sorry, I’m quite new to this

Thanks again

Ian

Ian, here is how I would have tried to do this by reading text file. I did try to get the text part into a handler but im rubbish at getting these to work. I’ve only set this to work by picking 2 images to merge as I can’t get a mental picture of your file naming strings. But it should give you some idea. Here is what the text looked like:

AAA, Cyan 100, Magenta 92, Yellow 1, Black 1, Pantone Reflex Blue C
BBB, Cyan 0 Magenta 97 Yellow 74 Black 0, Pantone 185 C
CCC, Cyan 13 Magenta 87 Yellow 0 Black 0, Pantone 225 C
DDD, Cyan 67 Magenta 0 Yellow 87 Black 0, Pantone 360 C

set CV_Tables to alias choose file with prompt "Where is the Colour Values text file?" without invisibles
set CVT to read (CV_Tables)
--
set FileA to choose file without invisibles
set FileB to choose file without invisibles
--
tell application "Finder"
	set theFileA to FileA as alias
	set theFileB to FileB as alias
end tell
--
tell application "Adobe Photoshop CS2"
	activate
	set display dialogs to never
	set ruler units of settings to pixel units
	open theFileA
	set docRefA to the current document
	tell docRefA
		set docNameA to name of docRefA
		change mode to multichannel
	end tell
	open theFileB
	set docRefB to the current document
	tell docRefB
		set docNameB to name of docRefB
		set docBaseName to getBaseName(docNameB) of me
		-- replace the cut & paste with duplicate
		duplicate channel 1 to end of docRefA
	end tell
	close docRefB without saving
	tell docRefA
		-- This is what I would have liked in a handler!!!
		repeat with x from 1 to (count of paragraphs) of CVT of me
			set y to paragraph x of CVT of me as string
			set z to count of words of y
			if word 1 of y as string is docBaseName of me then
				set myPMS to words 10 thru z of y
				set ASTID to AppleScript's text item delimiters
				set AppleScript's text item delimiters to space
				set myPMS to myPMS as string
				set AppleScript's text item delimiters to ASTID
				set myC to word 3 of y as integer
				set myM to word 5 of y as integer
				set myY to word 7 of y as integer
				set myK to word 9 of y as integer
			end if
		end repeat
		set properties of last channel to ¬
			{name:myPMS, kind:spot color channel, opacity:0, visible:true, channel color:{class:CMYK color, cyan:myC, magenta:myM, yellow:myY, black:myK}}
	end tell
end tell
--
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

Thanks Mark,

I’ve been trying to pick apart your script to understand what you have done.

The workflow produces a folder of eg. 5 greyscale tifs, 1 for each colour, with the name 200000_XX 0054.tif, 200000_XX 0653.tif {job number_colour name}. If you had an image in Photoshop and did Split channels, this is the same as my situation (5 separate files with spot colour on end of filename). Merge Channels puts greyscale tifs of the same size back together, but other than forcing a keyboard shortcut, I don’t think this is scriptable. It is also a little unpredictable which order it puts the channels in.

I’ll carry on perservering with it as I think it’s close.

Thanks to everyone

Ian

Ian The only merge options in PS scripting do not include what you are doing in the GUI you can merge layers or spot channels into the composite colour space. Do you have any composite stuff or just spot plates? if its the latter the order of the repeat loop for opening the images would not matter you would just need the end of the name string to look up the associated data from your text file. In the example shown a file named AAA would be coloured Pantone Reflex Blue C a file named BBB Pantone 185 C an so on. I have had a little time to add some more. As you can see I still haven’t got the handler working right yet.
My test text file looks like this:

0054, 100, 92, 1, 1, Pantone Reflex Blue C
0185, 0, 97, 74, 0, Pantone 185 C
0225, 13, 87, 0, 0, Pantone 225 C
0360, 67, 0, 87, 0, Pantone 360 C
0635, 36, 0, 7, 0, Pantone 635 C

File names like this:

200000_XX 0054.tif
200000_XX 0185.tif
200000_XX 0225.tif
200000_XX 0360.tif
200000_XX 0635.tif

set CV_Tables to alias choose file with prompt "Where is the Colour Values text file?" without invisibles
set CVT to read (CV_Tables)
--
set inputFolder to choose folder with prompt "Where is the folder of image files?" without invisibles
--
tell application "Finder"
	set filesList to files in inputFolder
	set myChannels to count of filesList
	set theFileA to item 1 of filesList as alias
end tell
--
tell application "Adobe Photoshop CS2"
	activate
	set display dialogs to never
	open theFileA
	set docRefA to the current document
	tell docRefA
		set docNameA to name of docRefA
		change mode to multichannel
		set docBaseName to getBaseName(docNameA) of me
		set colourID to items 11 thru 14 of docBaseName as string
		-- This is what I would have liked in a handler!!!
		repeat with x from 1 to (count of paragraphs) of CVT of me
			set y to paragraph x of CVT of me as string
			set z to count of words of y
			if word 1 of y is colourID then
				set myPMS to words 6 thru z of y
				set ASTID to AppleScript's text item delimiters
				set AppleScript's text item delimiters to space
				set myPMS to myPMS as string
				set AppleScript's text item delimiters to ASTID
				set myC to word 2 of y as integer
				set myM to word 3 of y as integer
				set myY to word 4 of y as integer
				set myK to word 5 of y as integer
			end if
			set properties of channel 1 to ¬
				{name:myPMS, kind:spot color channel, opacity:0, visible:true, channel color:{class:CMYK color, cyan:myC, magenta:myM, yellow:myY, black:myK}}
		end repeat
	end tell
end tell
--
repeat with i from 2 to myChannels
	tell application "Finder"
		set theFileB to item i of filesList as alias
	end tell
	tell application "Adobe Photoshop CS2"
		open theFileB
		set docRefB to the current document
		tell docRefB
			set docNameB to name of docRefB
			set docBaseName to getBaseName(docNameB) of me
			set colourID to items 11 thru 14 of docBaseName as string
			-- This is what I would have liked in a handler!!!
			repeat with x from 1 to (count of paragraphs) of CVT of me
				set y to paragraph x of CVT of me as string
				set z to count of words of y
				if word 1 of y is colourID then
					set myPMS to words 6 thru z of y
					set ASTID to AppleScript's text item delimiters
					set AppleScript's text item delimiters to space
					set myPMS to myPMS as string
					set AppleScript's text item delimiters to ASTID
					set myC to word 2 of y as integer
					set myM to word 3 of y as integer
					set myY to word 4 of y as integer
					set myK to word 5 of y as integer
				end if
			end repeat
			duplicate channel 1 to end of docRefA
		end tell
		close docRefB without saving
		tell docRefA
			set properties of last channel to ¬
				{name:myPMS, kind:spot color channel, opacity:0, visible:true, channel color:{class:CMYK color, cyan:myC, magenta:myM, yellow:myY, black:myK}}
		end tell
	end tell
end repeat
--
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

Mark,

I ran your script, but it came up with the error that myPMS was undefined, so it was failing to find the value in the lookup table. I had my text file and tifs set up the way you describe in your post.

I had wrangled your scripts into something of my own I thought would work, but it wouldn’t find the colour name from the master list. Will carry on testing.

Thanks

Ian

Ian, just loaded it back down off here and works fine again for me here. It is most likely down to the text handling which I must admit Im not good at. It does error if I save text file as .rtf as opposed to plain text in text edit. Not sure if something in the way you saved the text example is throwing this out. There are plenty of others here who are much better at bashing text and strings about, hopefully one of them may be able to help you with this bit, no need for them to have photoshop app.