PS Scripting: JavaScript Document.SaveAs TiffSaveOptions
Copy link to clipboard
Copied
Hello,
I have made some scripts to automate my workflow but now I have problems to make saving TIFF files from script working. I want to set image compression to LZW and color profile embedding to true- According to Adobe Photoshop CC Scripting Guide that shouldn'T be to hard. Example for JPEG (p. 32):
So I came up with the following code:
tiffSaveOptions = new TiffSaveOptions();
tiffSaveOptions.embedColorProfile = true;
tiffSaveOptions.imageCompression=TIFFEncoding.TIFFLZW;
When I debug the code, the first gives me the following
second line (embedColorProfile) sets image compression to NONE without setting embedColorProfile
third line set image compression to LZW
but I am not able to set embedColorProfile in any way
I have tried on a machine with an old CS4 installation and it works as intended.
I have Photoshop 2020 (21.2.1.265) and Photoshop CS6 installed
Extendscript Toolkit CC is version 4.0.0.1 ExtendedScript 4.5.5
OS is Windows 10 1909
Have I missed something or sees anybody the same behavior?
Explore related tutorials & articles
Copy link to clipboard
Copied
I do not know JavaScript so I steal code. Who do I steal from? One source is from Adobe Photoshop. It may not be the greatest idea Photoshop has a lot of bugs. However, in the case Adobe script export layers to files seem to have Save As code for many image file types with options for the a file type. I do not save Tiff files so here I would need the be the thief
///////////////////////////////////////////////////////////////////////////////
// Function: saveFile
// Usage: the worker routine, take our params and save the file accordingly
// Input: reference to the document, the name of the output file,
// export info object containing more information
// Return: <none>, a file on disk
///////////////////////////////////////////////////////////////////////////////
function saveFile( docRef, fileNameBody, fileInfo) {
switch (fileInfo.fileType) {
.
.
.
case tiffIndex:
var saveFile = new File(fileInfo.destination + "/" + fileNameBody + ".tif");
tiffSaveOptions = new TiffSaveOptions();
tiffSaveOptions.embedColorProfile = fileInfo.icc;
tiffSaveOptions.imageCompression = fileInfo.tiffCompression;
if (TIFFEncoding.JPEG == fileInfo.tiffCompression) {
tiffSaveOptions.jpegQuality = fileInfo.tiffJpegQuality;
}
docRef.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);
break;
.
.
.
default:
if ( DialogModes.NO != app.playbackDisplayDialogs ) {
alert(strUnexpectedError);
}
break;
}
return saveFile;
}
switch (fileInfo.tiffCompression) {
case TIFFEncoding.NONE: index = compNoneIndex; break;
case TIFFEncoding.TIFFLZW: index = compLZWIndex; break;
case TIFFEncoding.TIFFZIP: index = compZIPIndex; break;
case TIFFEncoding.JPEG: index = compJPEGIndex; break;
default: index = compNoneIndex; break;
}
Copy link to clipboard
Copied
Thanks for pointing out the Adobe scripts. I had totally forgotten about them.
Sometimes I think that all software is sent from hell. I have run the Export Layers to Files script with debugging and I see the same behavior for the TiffSaveOptions object (and the saved result) with this script. I believe that this is a bug with the ExtendScript debugger. But I have also found that saving the files is working as expected.
The setting for saving the ICC profile works but I had never realized that Windows 10 won't display the correct information for color representation in the file properties unless it is in the sRGB color space. For AdobeRGB or ProPhoto the file properties are only saying "Not Calibrated". So I thought that the profile was lost by saving the file. But checking with Adobe Bridge shows that the photo is still tagged with the correct profile. So that's either a shortcoming or a bug in Windows.
Rainer
Copy link to clipboard
Copied
May you say where in Data Browser tab of ESTK I can find tiffSaveOptions, or what to do to see it there?
Copy link to clipboard
Copied
You can simpy copy the following code into ESTK
#target photoshop
tiffSaveOptions = new TiffSaveOptions();
tiffSaveOptions.embedColorProfile = true;
tiffSaveOptions.imageCompression=TIFFEncoding.TIFFLZW;
by pressing F10 Photoshop will be startet and after pressing F10 again and reaching line 3 an object tiffSaveOptions will be create from the class TiffSaveOptions. In the Data Browser there is now a long list of objects. Just scroll down until you reacht letter T in the sort order. It should be after the method TiffSaveOptions()
By clicking the + symbol in front of it you should see the properties in the same way as shown in my original post (you have to scroll down again as the Data Browser will scroll up). By continuing debugging with F10 you can see that properties are changing.
Copy link to clipboard
Copied
Thank you. I missed doing it in debug mode 😉
Copy link to clipboard
Copied
Adobe is doing away with extendscript toolkit I never like using it for the way panels rapidly changes disturbed my eyes and concentration. I stopped using it anyway. I do not do the much scripting, I just use alerts as breakpoints with info... stupid me...

