Photoshop Actions problem

Hi there,
I have a very simple script that opens a tif or jpeg image and resaves it as an EPS in Photoshop, this process works fine but if the tif or jpeg contains any extra channels or layers instead of saving the file without any dialog/user intervention Photoshop displays the save window with a warning. I know that I could add to the action and make it flatten images etc but what I would like to know is if the save action encounters a problem can I be alerted? I’ve put a try statement in the script but this only works if Photoshop has a problem opening the file not if it encounters a problem whilst performing the action. Any suggestions would be appreciated!
Thanks,
Nik

saveaseps()

on saveaseps()
	set MasterFolder to (path to desktop as string) & "testing" as alias
	
	tell application "Finder"		
		set the the_items to every file of MasterFolder
		repeat with i from 1 to number of items in the_items
			set this_item to item i of the_items as alias
			set this_item_name to the name of this_item
			try
				tell application "Adobe Photoshop CS2"
					activate
					open this_item showing dialogs never
					do action "convert to eps" from "Default Actions"
				end tell
			on error theError
				tell application "Mail"
					set newmessage to make new outgoing message with properties {subject:"Photoshop had a problem processing " & this_item_name, content:theError}
					tell newmessage
						set visible to true
						make new cc recipient at end of cc recipients with properties {name:"Auto-Pre-Flight", address:"joeblogs@emailaddress.com"}
						send
					end tell
				end tell
			end try
			tell application "Finder"
				delete this_item
			end tell
		end repeat
	end tell
end saveaseps

Hi again,
I think I’ve gat a compromise, I’ve put a timeout in the script, then force quit Photoshop and relaunch it. This seems to do the trick put if there are any other suggestions then please post them.
Thanks,
Nik

saveaseps()

on saveaseps()
	set MasterFolder to (path to desktop as string) & "testing" as alias
	
	tell application "Finder"		
		set the the_items to every file of MasterFolder
		repeat with i from 1 to number of items in the_items
			set this_item to item i of the_items as alias
			set this_item_name to the name of this_item
			try
				with timeout of 300 seconds
					tell application "Adobe Photoshop CS2"
						activate
						open this_item showing dialogs never
						do action "convert to eps" from "Default Actions"
					end tell
				end timeout
			on error theError
				tell application "Mail"
					set newmessage to make new outgoing message with properties {subject:"Photoshop had a problem processing " & this_item_name, content:theError}
					tell newmessage
						set visible to true
						make new cc recipient at end of cc recipients with properties {name:"Auto-Pre-Flight", address:"joebloggs@emailaddress.com"}
						send
					end tell
				end tell
				set photoshop_process to "Adobe Photoshop CS2"
				set the_pid to (do shell script ("ps -auxwww | grep " & (quoted form of photoshop_process) & " | grep -v grep | awk '{print $2}' "))
				if the_pid is not "" then do shell script ("kill -9 " & the_pid)
				tell application "Adobe Photoshop CS2" to activate
			end try
			tell application "Finder"
				delete this_item
			end tell
		end repeat
	end tell
end saveaseps

I’m not sure what all you are doing with your action, but I would do the save commands using AppleScript rather than the actions:

set ThePath to (path to desktop) as string

tell application "Adobe Photoshop CS2"
	save document 1 in (ThePath & "TestEPS.eps") as Photoshop EPS with options {embed color profile:true, encoding:binary, halftone screen:false, image interpolation:false, PostScript color management:false, preview type:eight bit Mac OS, transfer function:false, vector data:false} appending lowercase extension with copying
end tell

Note: I put the extension into the file name because without it PS doesn’t seem to recognize the appending part of the save command. This should take care of the flattening “on the fly” and since it is making a copy of the file you just need to add “close saving no” after the save command and move on to the next file. If you have other functions in your action you could either try to move those into AppleScript code and get ride of the action compleatly or just “turn off” the save function and save it using AppleScirpt.

Thanks for the post Jerome, because I want to leave the file as close to the original as possible I’d prefer not to flatten or remove extra channels without human eyes viewing it first, in case of any visual changes to the file. The script that I posted is part of a much larger one and is processing a great deal of files. If the file I’m processing doesn’t have any extra channels or layers then the action saves the file without any problems but when it finds extra channels/Layers it wants to know what to do with them and so presents the warning window. I’m happy that it doesn’t just save the file but becuase this process is running on an Xserve that nobody particularly watches if this problem occurs the script just hangs until timing out and no further files are processed.
Thanks again,
Nik

The save command above saves a copy of the opened file as an eps, leaving the original alone so it should work for you since photoshop eps files do not support layers. You could always check if there are more than one layer or extra channels in the document and e-mail someone the offending file name so that they can attend to it while the script continues on with the other files.

Hi Jerome,
Checking for layers and extra channels before performing my action definately would make sence and would avoid waiting for a timeout. I’m not sure of the syntax for this, if you can give me any pointers that would be great.
Thanks,
Nik

tell application "Adobe Photoshop CS2"
	set x to count of layers of document 1
	set y to count of channels of document 1
end tell

There will be 1 layer in a flattened document, though one that is not flattened could only contain 1 layer as well. Using the generic “Layers” will treat a layer set as a layer, ie if there is one layer and one layer set (which contains 5 layers) then the script will recieve a count of 2 layers from this code. You should be able to look into PS’s dictionary to drill down further iin how to find out about the layers and layer sets.

Thanks for the pointers Jerome, I should be able to run a more efficient script now!:smiley:

A slower method than Jerome’s example of saving a copy as EPS. You’ll have to check but Im almost certian that this method tosses spot channel data. I don’t know if that would be an issue for you, is to test the file before running your action.

property Default_Path : (path to desktop folder as Unicode text) & "Test.eps"

tell application "Adobe Photoshop CS2"
	activate
	set docRef to the current document
	tell docRef
		-- Anything except a background layer
		if (count of art layers) > 1 or (count of layer sets) > 0 or ((count of art layers) is 1 and not background layer of layer 1) then flatten
		-- Example is based on CMYK 4 channel the composite is not counted
		if (count of channels) > 4 then
			set spot_channels to (every channel whose kind is spot color channel)
			repeat with this_spot in reverse of spot_channels
				merge this_spot -- or delete which ever you want
			end repeat
			set sac_channels to (every channel whose kind is selected area channel)
			repeat with this_sac in reverse of sac_channels
				delete this_sac
			end repeat
			set mac_channels to (every channel whose kind is masked area channel)
			repeat with this_mac in reverse of mac_channels
				delete this_mac
			end repeat
		end if
		save docRef in file (Default_Path as string) as Photoshop EPS with options ¬
			{class:EPS save options, embed color profile:true, encoding:binary, preview type:eight bit TIFF}
	end tell
	close current document saving no
end tell