1

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
  • I'm wondering why you don't just record an Action in PShop to change the profile, then do it as a Batch process... – Tetsujin Jun 29 '17 at 7:57
  • @Tetsujin, good question. Mainly because I don't intend on doing this manually every time it needs to be done. This script is for a commercial printer that will run this process on a regular basis (weekly) in conjunction with other tasks that are taking place in Esko's Automation Engine software. Automation Engine supports running scripts, therefore, this was the most seamless way to integrate the conversion. – Matt Furr Jul 15 '17 at 5:00
1

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):

save current document in file newFilePath as TIFF with options {class:TIFF save options, embed color profile:true, save layers:true, save spot colors:true} appending lowercase extension

How I figured it out:

Step 1:

First thing I did was open a new file in the Script editor and ran:

tell application "Adobe Photoshop CC 2017"

    return current document

end tell

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...

set fileName to "Filename.tif"
set newFilePath to "/Users/joonaspaakko/Desktop/test/output/" & fileName
tell application "Adobe Photoshop CC 2017"

    convert to profile "High Quality Print" 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

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .