I am trying to write a script to do some tasks in Photoshop. I have cobbled together a few scripts and I am fairly happy with the script (as it does work!). I pinched the first bit from a script that was included as an example batch script from Adobe however I do not want it to select a folder and it’s contents just a specific file. This is where I am having the problems! Whatever I try I either get an error or the file is renamed wrong! What I need to do is select a Photoshop file run the script and save it under an amended name. To clarify:
Select this file:
“Any name-WHITE.tif”
script then changes background colour and saves as:
“Any name-c5m6y2k5.tif”
then changes image size and saves new file as:
“Any nameSml-c5m6y2k5.tif”
The files will always have “WHITE” at the end of the name so I need to remove it and replace it with the “c5m6y2k5” which is the variable that is asked in the dialogs. The files will always be saved in the same folder the original file came from and I ideally need to make sure the files aren’t too long. Is it possible for the script to give a warning if the file name is too long?
set tempFolderName to "Temp"
set inputFolder to choose folder
tell application "Finder"
set filesList to files in inputFolder
if (not (exists folder ((inputFolder as string) & tempFolderName))) then
set outputFolder to make new folder at inputFolder with properties {name:tempFolderName}
else
set outputFolder to folder ((inputFolder as string) & tempFolderName)
end if
end tell
tell application "Adobe Photoshop 7.0"
set display dialogs to never
close every document saving no
end tell
repeat with aFile in filesList
set fileIndex to 0
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
set cyanValue to text returned of (display dialog "Cyan Value?" default answer "" buttons {"Cancel", "OK"} default button 2 with icon 1)
set magentaValue to text returned of (display dialog "Magenta Value?" default answer "" buttons {"Cancel", "OK"} default button 2 with icon 1)
set yellowValue to text returned of (display dialog "Yellow Value?" default answer "" buttons {"Cancel", "OK"} default button 2 with icon 1)
set blackValue to text returned of (display dialog "Black Value?" default answer "" buttons {"Cancel", "OK"} default button 2 with icon 1)
end tell
tell application "Adobe Photoshop 7.0"
open theFile
set docRef to the current document
set myTiffOptions to {class:TIFF save options, image compression:LZW, byte order:Mac OS, save alpha channels:true, save spot colors:true, embed color profile:true, save layers:false}
if (mode of docRef is not CMYK) then
change mode docRef to CMYK
end if
if (bits per channel of docRef is sixteen) then
set bits per channel of docRef to eight
end if
make new art layer in docRef with properties {blend mode:multiply}
do action "Path to selection" from "Default Actions.atn"
fill selection of docRef with contents {class:CMYK color, cyan:(cyanValue & ".0"), magenta:(magentaValue & ".0"), yellow:(yellowValue & ".0"), black:(blackValue & ".0")}
set docName to name of docRef
set docBaseName to getBaseName(docName) of me
set newFileName to (outputFolder as string) & docBaseName & "-" & {"c" & cyanValue, "m" & magentaValue, "y" & yellowValue, "k" & blackValue}
save docRef in file newFileName as TIFF with options myTiffOptions appending lowercase extension with copying
--resize image and save as small version
resize image current document width 10
set docName to name of docRef
set docBaseName to getBaseName(docName) of me
set newFileName to (outputFolder as string) & docBaseName & "S-" & {"c" & cyanValue, "m" & magentaValue, "y" & yellowValue, "k" & blackValue}
save docRef in file newFileName as TIFF with options myTiffOptions appending lowercase extension with copying
close docRef without saving
end tell
end repeat
-- Returns the document name without extension (if present)
--I'm not sure what this bit does and if I need it?
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
I hope this is clear enough to understand and any comments or suggestions about the script will help me to try and understand the whole AppleScript thing more than I do now, which isn’t much!
Many thanks for any help.