Photoshop Save as EPS plus text

Is it possible to add text to a filename while saving an (in this case) EPS from Photoshop using a script
this is what I need: filename.eps.lay
All the files which need to be renamed are automaticly places (by the script in a fixed folder)
If this is not possible, howto auto rename with the finder or shellscript

–Peter-- Netherlands :cool:

on adding folder items to this_folder after receiving these_items
tell application “Finder”
if not (exists folder “Done” of this_folder) then
make new folder at this_folder with properties {name:“Done”}
end if
set the destination_folder to folder “Done” of this_folder as alias
set the destination_directory to POSIX path of the destination_folder
end tell
repeat with an_item in these_items
tell application “Adobe Photoshop CS2”
with timeout of 10 seconds
open an_item
set display dialogs to never
set an_item to current document
change mode an_item to RGB
resize image current document resolution 72 resample method bicubic
set myoptions to {class:EPS save options, encoding:medium quality JPEG, preview type:eight bit TIFF}
save current document as Photoshop EPS in destination_folder with options myoptions appending lowercase extension without copying
close current document saving no
repeat with an_item in these_items
end repeat
end timeout
end tell
end repeat
end adding folder items to

Hi

Look at a script which comes with Mac os X “Add to file Names”
it will add a suffix or a prefix to a bunch of selected items

If you want to save the file out of photoshop with the “.lay” in the name then all you have to do is add the new file name to the save path. You probably want to save without appending the extension and build adding the extensions (.eps.lay) into the the definition of the new file name. You will need to add in a rutine to check for and remove the old extension from the name if neccessary.

Hi Jerome Thanks for looking in to this.
Indeed I need this string: filename.eps.lay
If I leave out “appending lowercase extension without copying” how do I create the new output filename.eps.lay
Can you give me an example?

Not a fan of these folder things but here goes. Note that for this I swapped your file re-naming around. Personally “.” goes before extension “only” but each to their own. The handler here would fail on your file naming I think!

on adding folder items to this_folder after receiving these_items
	tell application "Finder"
		if not (exists folder "Done" of this_folder) then
			make new folder at this_folder with properties {name:"Done"}
		end if
		set the destination_folder to folder "Done" of this_folder as alias
		-- set the destination_directory to POSIX path of the destination_folder
	end tell
	repeat with an_item in these_items
		tell application "Finder"
			set theFile to an_item as alias
		end tell
		tell application "Adobe Photoshop CS2"
			with timeout of 10 seconds
				activate
				set display dialogs to never
				set UserPrefs to properties of settings
				set ruler units of settings to pixel units
				open theFile
				set docRef to the current document
				set docName to name of docRef
				set docBaseName to getBaseName(docName) of me
				tell docRef
					if (mode is not RGB) then
						change mode to RGB
					end if
					if (bits per channel is sixteen) then
						set bits per channel to eight
					end if
					resize image resolution 72 resample method bicubic
					set newFileName to (destination_folder as string) & docBaseName & "_lay.eps"
					save docRef in file newFileName as Photoshop EPS with options ¬
						{class:EPS save options, embed color profile:true, encoding:medium quality JPEG, preview type:eight bit TIFF} with copying
					close docRef without saving
				end tell
			end timeout
		end tell
	end repeat
end adding folder items to
--
tell application "Adobe Photoshop CS2"
	set ruler units of settings to ruler units of UserPrefs
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

Mark,

Just a guess but the .eps.lay may be neccessary for some type of OPI workflow, that is whare I have seen the .lay added to files in the past (though those were always created by the server).

retepp,

How consistant are the file names? As Mark said “.” should be mainly used for extensions, but in reality there are times when they are neccessary such as working with a clients file naming convention. In the files that you are processing will the extension be in the file name of the original image? So you need to worry about 4 character extensions (like InDesings “.INDD”) or will they only be 3 character extensions? The more control you have over the incoming files and the more consistant they are then the easier it will be to name the processed files the way you want.

Jerome, you are quite right. I was more trying to make the point about the limitations of this handler. Depending on peters file naming this may fail in my case it won’t just a point to consider. The rest should be sound. BTW if I change the name to peter’s option the result is “filename.eps.eps” with or without appending!

The filename MUST be filename.eps.lay
Fils to be processed are always EPS with lowrecase extension eps
Indeed it’s used for creating OPI images
At this point this is beiing done by our (AIX-Helios OPI) server but we realy like to abandon this one, so we are looking for a quick way to create OPI lowres images on one of our XServe’s.
Debabelizer won’t work because I need an EPS with Tiff preview
Graphic Convertor can’t handle large files verry well
That’s way I am trying to get this done trough applescript

Thanks for looking in to this I really appreciate it!!

–Peter–

Peter, you could just change this line:

set newFileName to (destination_folder as string) & docBaseName & ".eps"

then have finder rename the files after. This could be done with the built in Applescript “Add to file names” or you could choose to build it in as part of this routine. In my case nither CS or CS2 will allow your naming convention.

Okay Mark,
let’s say I want to build a finder rename routine into my script, how do I do this?
In automator it’s quit simple but I like to embed it in my script:
processed images are in destination folder “done” they need to be renamed from .eps to .eps.lay (search&replace)
If possible I’d like to move the .eps.lay files back into the top folder - in this case I need a “filter” on the extension otherwise I get into a loop
Can this be done if yes would you be so kind to assist me?
B.t.w. Your script will not trigger PS to open and process the added files

–Peter–

The code that Mark has above should work by changing:

set newFileName to (destination_folder as string) & docBaseName & "_lay.eps"

to

set newFileName to (destination_folder as string) & docBaseName & ".lay"

and

save docRef in file newFileName as Photoshop EPS with options {class:EPS save options, embed color profile:true, encoding:medium quality JPEG, preview type:eight bit TIFF} with copying

to

savein file newFileName as Photoshop EPS appending no extension with options {class:EPS save options, embed color profile:true, encoding:medium quality JPEG, preview type:eight bit TIFF}

Now, the name taken from PS should have the extention “.eps” in it so there is no need to worry about that, you just need to add the “.lay” to it. Also note that I took “docRef” out of t he save command, since it is within the tell block for docRef there is no need for it and may be causing the script to error out. I also took out the wth copying since you are giving it a new path with the change in name there is no need for this.

Now this will get you a file, the bigger problem in what you are doing is going to be the server side replacement of the images when before it sends the post script to the rip. That is one of the reasons people buy server software like Helios and Xinet. I don’t know if OS X server has anything that will do this built in. You also might need to do more to the eps file that you save to get the appropriate OPI commenting in for the server software to read so that it properly links up to the high resolution image. The last option I guess is that you live with low resoltion versions for most of the workflow and only swap in the high res versioins at the end of the project when you go to PDF.

Hi Jerome,
Thanks for your input - I wiil check it tomorrow (It’s 16.00 in th Netherland right now)
I made a script for Indesign that replaces the .eps.lay files for the .eps files.
In our case not so difficult because the low and highres images reside in the same folder(s)
I know that for a large group of people OPI is a somewhat outdated workflow but some of our customers dowload the lowres from our database and use them in their jobs. We relink and replace them with our scripts and process the jobs to PDF or CTP

–Peter–

The only thing that I think is ouotdating OPI is InDesign’s reliance on the host computer for flattening the page, and therefore any image with transparency associated with it, such as one with type above that has a drop shadow, will use the palced image for flattening instead of the high res image. If all you need to do is relink and output to another file then there shouldn’t be a problem. If on the other hand you or your clients need to print with the low res in place but need the high res images in the print out then you could run into problems.

Hi Mark an Jerome,
It ALMOST works
Jerome, I had to change set newFileName to (destination_folder as string) & docBaseName & ".lay to set newFileName to (destination_folder as string) & docBaseName & ".eps.lay
The only thing is that PS will not close the new .eps.lay file so the command close docRef without saving is incorrect
The only solution as far as I can see is to put an end tell after the save in file…etc
folowed by tell application “Photoshp CS2”
close current document without saving
–or is there a better way?

So here’s the script:

on adding folder items to this_folder after receiving these_items
tell application “Finder”
if not (exists folder “Done” of this_folder) then
make new folder at this_folder with properties {name:“Done”}
end if
set the destination_folder to folder “Done” of this_folder as alias
– set the destination_directory to POSIX path of the destination_folder
end tell
repeat with an_item in these_items
tell application “Finder”
set theFile to an_item as alias
end tell
tell application “Adobe Photoshop CS2”
with timeout of 300 seconds
activate
set display dialogs to never
set UserPrefs to properties of settings
set ruler units of settings to pixel units
open theFile
set docRef to the current document
set docName to name of docRef
set docBaseName to getBaseName(docName) of me
tell docRef
if (mode is not RGB) then
change mode to RGB
end if
if (bits per channel is sixteen) then
set bits per channel to eight
end if
resize image resolution 72 resample method bicubic
set newFileName to (destination_folder as string) & docBaseName & “.eps.lay”
save in file newFileName as Photoshop EPS appending no extension with options {class:EPS save options, embed color profile:false, encoding:medium quality JPEG, preview type:eight bit TIFF}
end tell
tell application “Adobe Photoshop CS2”
close current document without saving
end tell
end timeout
end tell
end repeat
end adding folder items to

tell application “Adobe Photoshop CS2”
set ruler units of settings to ruler units of UserPrefs
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

–Peter–:slight_smile:

Peter,

You are correct about the document reference breaking with the save command. Also since you kept in the handler to take off the extension then you needed to add that back in. Below is a quick edit to what Mark and you put together which should work, though I did not test it as a folder action.

The reason that I eliminated the handler to remove the extension is that it starts at the beginning of the file name and stops at the first period. Therefore if you have a file which is “JobNumber.Chapter.Image_1.eps” then your new name would be “JobNumber.eps.lay”. This may not be part of your file naming convention but I have seen it used by a number of companies. There are other ways to remove the extension, but that might not be necessary. With OS X the file name, whether it is displayed or not, is the name and the extension. Therefore as long as you are processing “eps” files in the folder then it will be part of the name and all you should need to do is add on the “.lay”. If you have other files that might be put in there such as a tif then it will keep that extension in the name though you could filter those out in other ways or go ahead and rewrite an extension removal handler that will only get ride of an extension and leave other things delimitated by a period alone.

This is really the thing that takes the most time in scripting a workflow, figuring out all the potential ways that users can “break” the script and find ways to take those into account and do the processes as intended.

I hope this helps, it is not necessarily the best way to do things just the way that I would approach it based on the information that you have given. I would personally add in error checking to make sure that it is only processing eps files, and probably add in the ability to do tif’s and psd’s as well. I would also change the “.lay” to “-FPO.eps”, if you are getting rid of the helios workflow then there is no need to keep their extension for the low res placement image.

Jerome

on adding folder items to this_folder after receiving these_items
	tell application "Finder"
		if not (exists folder "Done" of this_folder) then
			make new folder at this_folder with properties {name:"Done"}
		end if
		set the destination_folder to folder "Done" of this_folder as alias
	end tell
	repeat with an_item in these_items
		tell application "Adobe Photoshop CS2"
			with timeout of 300 seconds
				activate
				set display dialogs to never
				set UserPrefs to properties of settings
				set ruler units of settings to pixel units
				open alias an_item
				tell current document
					if (mode is not RGB) then change mode to RGB
					if (bits per channel is sixteen) then set bits per channel to eight
					resize image resolution 72 resample method bicubic
					set docName to name
					set newFileName to (destination_folder as string) & docName & ".lay"
					save in file newFileName as Photoshop EPS appending no extension with options {class:EPS save options, embed color profile:false, encoding:medium quality JPEG, preview type:eight bit TIFF}
					close without saving
				end tell
			end timeout
		end tell
	end repeat
	tell application "Adobe Photoshop CS2"
		set ruler units of settings to ruler units of UserPrefs
	end tell
end adding folder items to

Hi Jerome,
Thanks for this one, it works!
I only changed open alias an_item to open an_item thats all

Let’s say I want to take ik a step further:
save the lowres in the main folder and not in the done folder (I created this one because it gets in a loup if you dont)
I probably need to filter out the .lay extension at the beginning of the script.
I got this question from one of our opeterators - It’s easier to check if all the files are done and to pick them up for copying to their final destination.
Can you give me an example how to do this?

–Peter–:smiley:

I’m not experienced with folder actions so I may be getting this wrong. What I think would happen is the script is triggered each time something is added to the foler, so when PhotoShop saves the file to the folder then it is going to launch the script again with the new file and try to process that. Because of this you will end up in quite a few loops by having the files saved to the folder with the action attached to it. The best way to deal with that would be to have some destination folder as you have done, you could even have the script move the original file to the destination folder when it is done processing. To filter out the lay files you might try:

on adding folder items to this_folder after receiving these_items
	tell application "Finder"
		if not (exists folder "Done" of this_folder) then
			make new folder at this_folder with properties {name:"Done"}
		end if
		set the destination_folder to folder "Done" of this_folder as alias
	end tell
	repeat with an_item in these_items
		if characters ((count of an_item) - 3) through (count of an_item) of an_item as string is not ".lay" then
			tell application "Adobe Photoshop CS2"
				with timeout of 300 seconds
					activate
					set display dialogs to never
					set UserPrefs to properties of settings
					set ruler units of settings to pixel units
					open alias an_item
					tell current document
						if (mode is not RGB) then change mode to RGB
						if (bits per channel is sixteen) then set bits per channel to eight
						resize image resolution 72 resample method bicubic
						set docName to name
						set newFileName to (destination_folder as string) & docName & ".lay"
						save in file newFileName as Photoshop EPS appending no extension with options {class:EPS save options, embed color profile:false, encoding:medium quality JPEG, preview type:eight bit TIFF}
						close without saving
					end tell
				end timeout
			end tell
		end if
	end repeat
	tell application "Adobe Photoshop CS2"
		set ruler units of settings to ruler units of UserPrefs
	end tell
end adding folder items to

This is probably not the most effecient way of dealing with this since if you are processing 100 files then it is going to loop through the 100 .lay files as they are saved as well, but it should not process those files in PS.

Your are right, saving the original files to the destination folder is the way to go - why didn’t I think of that!!
Can it be done in the same script?

(b.t.w, if characters ((count of an_item) - 3) through (count of an_item) of an_item as string is not “.lay” then… didn’t work)

–Peter–

Added a line to tell the finder to move the file after the photoshop file has been closed but before repeating to the next file. Also removed the if statemnet to check for .lay files.

on adding folder items to this_folder after receiving these_items
	tell application "Finder"
		if not (exists folder "Done" of this_folder) then
			make new folder at this_folder with properties {name:"Done"}
		end if
		set the destination_folder to folder "Done" of this_folder as alias
	end tell
	repeat with an_item in these_items
		tell application "Adobe Photoshop CS2"
			with timeout of 300 seconds
				activate
				set display dialogs to never
				set UserPrefs to properties of settings
				set ruler units of settings to pixel units
				open alias an_item
				tell current document
					if (mode is not RGB) then change mode to RGB
					if (bits per channel is sixteen) then set bits per channel to eight
					resize image resolution 72 resample method bicubic
					set docName to name
					set newFileName to (destination_folder as string) & docName & ".lay"
					save in file newFileName as Photoshop EPS appending no extension with options {class:EPS save options, embed color profile:false, encoding:medium quality JPEG, preview type:eight bit TIFF}
					close without saving
				end tell
			end timeout
		end tell
		tell application "Finder" to move alias an_item to destination_folder
	end repeat
	tell application "Adobe Photoshop CS2"
		set ruler units of settings to ruler units of UserPrefs
	end tell
end adding folder items to

Hi Jerome,
Thanks again for your input
I had to change two lines though:
open alias an_item to open an_item
and
tell application “Finder” to move alias an_item to destination_folder to tell application “Finder” to move an_item to destination_folder

What I found out is that it only works when you move files into the folder. With copying PS tries to open the file while its not completely arrived yet. There is a script called Folderaction with polls a folder but I am unable to put in thePS handling
(see below)
Don’t know if I will use it but it looks prommesing and works perfectly as is
I can’t find the right syntax for opening a file using this script
any ideas? - look for:
on ProcessThisFile(theFile)
– your file processing code goes here.

Created by Kevin Meany:

(* A script to behave as a folder action replacement when files are copied into the folder which would have had a folder action script attached and the files are either large or being copied over the network. This script is designed to avoid the problem where a folder action will trigger before a file is completely copied.

To use the script you will need to replace the code in ProcessThisFile with your own code. Do not try and add this script as a folder action. Just run the script and it will ask you to specify the folder to watch.

The author accepts no responsibility as a result of running this script.
Kevin Meaney ktam@yvs.eu.com
http://www.yvs.eu.com/
*)
property debugMe : true – set to false when you want to use this script in a production environment.
property delayTime : 10 – seconds - set to whatever value you feel is appropriate for your situation.
property fileNameList : {}
property fileSizeList : {}
property fileProcessedList : {}
property folderToProcess : missing value

on run
set folderToProcess to choose folder with prompt “Select Folder to process files”
set {fileNameList, fileSizeList, fileProcessedList} to {{}, {}, {}}
end run

on idle
try
my dd(“Checking for differences in “” & (folderToProcess as Unicode text) & “”…”)
set startTime to current date
set {newNameList, newSizeList} to my CreateFileNameSizeLists(folderToProcess)
set {filesToProcess, newNewNameList, newNewSizeList} to {{}, {}, {}}
repeat with j from 1 to (count newNameList)
set {addedToListToBeProcessed, newName, newSize} to {false, newNameList’s item j, newSizeList’s item j}
repeat with i from 1 to (count fileNameList)
set {fileName, fileSize} to {fileNameList’s item i, fileSizeList’s item i}
if fileName = newName then
if newSize is not 0 and newSize = fileSize then
my dd(“Adding “” & fileName & “” to list of files to be processed…”)
set {addedToListToBeProcessed, filesToProcess’s end} to {true, fileName}
exit repeat
end if
end if
end repeat
if not addedToListToBeProcessed then
if fileProcessedList does not contain newName then
–my dd(“Adding “” & (folderToProcess as Unicode text) & newName & “” to new file lists…”)
set {newNewNameList’s end, newNewSizeList’s end} to {newName, (info for (((folderToProcess as Unicode text) & newName) as alias))'s size}
end if
end if
end repeat
set {fileNameList, fileSizeList} to {newNewNameList, newNewSizeList}
repeat with i from 1 to (count filesToProcess)
set fileProcessedList’s end to filesToProcess’s item i
end repeat
my ProcessFiles(filesToProcess)
set diffTime to ((current date) - startTime)
if (diffTime is greater than or equal to delayTime) then
return 1
else
return delayTime - diffTime
end if
on error e
my dd("Error: " & e)
–set the clipboard to e
end try
end idle

on ProcessFiles(theFiles)
repeat with i from 1 to (count theFiles)
my dd(“Processing “” & ((folderToProcess as Unicode text) & theFiles’s item i) & “”…”)
my ProcessThisFile(((folderToProcess as Unicode text) & theFiles’s item i) as alias)
end repeat
if theFiles is not {} then my dd("Number of processed items: " & (count theFiles))
end ProcessFiles

on ProcessThisFile(theFile)
– your file processing code goes here.
set testFolderName to “TestFolder”
my dd(“Copying Filename: “” & (info for theFile)'s name & “” to “” & testFolderName & “”…”)
tell application “Finder”
try
set testFolder to ((path to desktop folder as Unicode text) & testFolderName & “:”) as alias
on error
set testFolder to (make new folder at desktop with properties {name:testFolderName}) as alias
end try
duplicate theFile to testFolder with replacing
end tell
end ProcessThisFile

on CreateFileNameSizeLists(theFolder)
set folderList to list folder theFolder without invisibles
set {myNameList, mySizeList} to {{}, {}}
repeat with j from 1 to (count folderList)
if (folderList’s item j)'s character 1 is not “.” then
set theInfo to info for ((theFolder as Unicode text) & (folderList’s item j) as alias)
– if (theInfo’s folder) then (*perhaps we want to copy folders *)
set {myNameList’s end, mySizeList’s end} to {theInfo’s name, theInfo’s size}
– end if
end if
end repeat
return {myNameList, mySizeList}
end CreateFileNameSizeLists

on dd(m)
if m starts with “Error:” then
activate
beep 2
if (display dialog m buttons {“Quit”, “OK”} default button 2 with icon 0)'s button returned = “Quit” then quit
else if debugMe then
activate
if (display dialog m buttons {“Quit”, “OK”} default button 2 with icon 1 giving up after 1)'s button returned = “Quit” then quit
end if
end dd