I'm using AppleScript to process a folder of TIFF images that need to be converted to a specific CMYK profile in Photoshop. The script first asks for a folder containing the images and then prompts for an output folder location. However, I get the following error when running the script:
Adobe Photoshop CC 2015 got an error: Can’t get current document.
The first thing I tried was to remove current
from the save command. It looks Photoshop is actually opening and saving the document(s) after doing this, however, the TIFFs are not in the folder specified in newFilePath
. Not sure how I should be handling this since it is supposed to process multiple files. The current script is below:
on run
tell me to open {choose folder}
end run
on open droppedItems
set destFolder to choose folder with prompt "Select Output Folder"
repeat with anItem in droppedItems
tell application "Finder"
-- Make sure each item is processed by this script is a folder
if class of item anItem is not folder then
-- Not a folder, notify the user of the error
display dialog "Please drop folders containing images"
else
-- A folder, get the Adobe Photoshop files and process them
set fileList to (every file of anItem) as alias list
end if
end tell
HPConvert(fileList, destFolder)
end repeat
end open
-- fileList is a list of aliases to Photoshop files
-- destFolder is an alias to a folder where the converted TIFFs are to be saved
on HPConvert(fileList, destFolder)
set destPath to destFolder as string
repeat with aFile in fileList
tell application "Finder" to set fileName to name of aFile
set newFilePath to destPath & fileName
tell application "Adobe Photoshop CC 2015"
open aFile
convert to profile "CGATS21_CRPC6 V2" intent absolute colorimetric with dithering
save current document in file newFilePath as TIFF with options {embed color profile:true, save layers:true, save spot colors:true} appending lowercase extension
close current document saving no
end tell
end repeat
end HPConvert
Best Answer
The problem appears to be the tiff options.
It's missing in the front of the object
class:TIFF save options,
That line as a whole (as it should be):
How I figured it out:
Step 1:
First thing I did was open a new file in the Script editor and ran:
Sure enough returns a document name as long as a document is open in PS. So no surprises there.
Step 2.
Took your script and stripped away all but the essentials and replaced input and output with static values. Well technically the input was just an open document...
Still complains about the document, but I know that is not the issue based on my first test.
Step 3.
So I took a look at the reference document for applescript and in there I looked at the tif save example. Can be found if you search for:
save current document in file myFile as TIFF
in the pdf.I'm not too experienced with Applescript in general let alone scripting Photoshop with it... So I don't know if there are better ways to debug the code, but Script Editor was complaining about that
save
line and highlighting it, so I figured that is where the error must be... or around that area.Just manually looked for differences and possible syntax errors, and I found out it was missing the
class:TIFF save options,
in the beginning of the tif options object and adding that in fixed the error.