Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

tifSaveOptions not saving metadata (Keywords etc.)

Participant ,
Jul 26, 2023 Jul 26, 2023

Hey community, I am saving a tif vis a script using the following code and somehow the metadata is not saved with the file. I can't find any info in the reffernce PDF. Lat thing I tried adding is the "annotations". But to no avail.

 

Is there something I need to do outside of the script while photoshop and the file are open? Or is this normal when saving a file via script?

 

    //Set the TIF options
    tifSaveOptions = new TiffSaveOptions( );
    tifSaveOptions.alphaChannels = false;
    tifSaveOptions.annotations = true;
    tifSaveOptions.imageCompression = TIFFEncoding.TIFFZIP;
    tifSaveOptions.layerCompression = LayerCompression.ZIP;
    tifSaveOptions.layers = true;
    
    // Save
    activeDocument.saveAs( saveFile,tifSaveOptions, true,Extension.LOWERCASE );

 

Thanks & Cheers, Alex

TOPICS
Actions and scripting , Windows
552
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 26, 2023 Jul 26, 2023

That code is incomplete.

 

I have tested the following code on the Mac in versions 2021, 2022 and 2023 and the saved TIFF has the metadata found in the original file.

 

/* 
Save As TIFF with confirmation to overwrite
*/

#target photoshop

// Check for open doc - success
if (app.documents.length !== 0) {
    // Strip the file extension
    var docName = app.activeDocument.name.replace(/\.[^\.]+$/, '');
    // Offer a prompt to name the file using the original name as default (invalid characters 
...
Translate
Adobe
Community Expert ,
Jul 26, 2023 Jul 26, 2023

That code is incomplete.

 

I have tested the following code on the Mac in versions 2021, 2022 and 2023 and the saved TIFF has the metadata found in the original file.

 

/* 
Save As TIFF with confirmation to overwrite
*/

#target photoshop

// Check for open doc - success
if (app.documents.length !== 0) {
    // Strip the file extension
    var docName = app.activeDocument.name.replace(/\.[^\.]+$/, '');
    // Offer a prompt to name the file using the original name as default (invalid characters are not considered)
    var docNameInput = prompt('Enter a filename (without extension):', docName);
    // Ensure that a filename extension if manually entered is removed
    var docNameOutput = docNameInput.replace(/\.[^\.]+$/, '');
    // Set the original doc source path
    var origPath = app.activeDocument.path.fsName;
    // Select a save location
    var docPath = Folder.selectDialog('Select a folder to save the TIFF image to...', origPath);
    // File save, path & name
    var saveFileTIFF = new File(docPath + '/' + docNameOutput + '.tif');
    // Conditional overwrite check
    if (saveFileTIFF.exists) {
        // true = 'No' as default active button
        if (!confirm("File exists, overwrite: Yes or No?", true))
            // throw alert("Script cancelled!");
            throw null;
    }

    // Call the TIFF function
    saveTIFF(saveFileTIFF);

    // TIFF function
    function saveTIFF(saveFileTIFF) {
        tiffSaveOptions = new TiffSaveOptions();
        tiffSaveOptions.embedColorProfile = true;
        // ByteOrder.MACOS or ByteOrder.IBM
        tiffSaveOptions.byteOrder = ByteOrder.IBM;
        tiffSaveOptions.transparency = true;
        tiffSaveOptions.layers = true;
        tiffSaveOptions.layerCompression = LayerCompression.ZIP;
        tiffSaveOptions.interleaveChannels = true;
        tiffSaveOptions.alphaChannels = true;
        tiffSaveOptions.annotations = true;
        tiffSaveOptions.spotColors = true;
        tiffSaveOptions.saveImagePyramid = false;
        // NONE | JPEG | TIFFLZW | TIFFZIP
        tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;
        app.activeDocument.saveAs(saveFileTIFF, tiffSaveOptions, true, Extension.LOWERCASE);
    }

    // Save notification
    alert('TIFF saved!');

    // Check for open doc - failure
} else {
    alert('You must have a document open!');
}

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 27, 2023 Jul 27, 2023

Thanks @Stephen Marsh ! 

I have to admit, this is (one) my Billy Madison moment(s). Because I create a new file in my script, it has no idea about the metadata. Sorry to have wasted your time!

 

For completion sake, here the full code where I save the file:

function SaveTIFF( saveFile ) {
        
    //Set the TIF options
    tifSaveOptions = new TiffSaveOptions( );
    tifSaveOptions.alphaChannels = false;
    tifSaveOptions.annotations = true;
    tifSaveOptions.imageCompression = TIFFEncoding.TIFFZIP;
    tifSaveOptions.layerCompression = LayerCompression.ZIP;
    tifSaveOptions.layers = true;
    
    // Save the file
    activeDocument.saveAs( saveFile,tifSaveOptions, true,Extension.LOWERCASE );
     
    // Close open document without saving
    activeDocument.close(SaveOptions.DONOTSAVECHANGES)
    
    // Open the newly created file
    app.open(saveFile);    
}

*OP now Goggling "how to copy metadata to a new file in Photoshop"

 

Cheers, Alex

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 27, 2023 Jul 27, 2023

@alex.furer wrote:

Thanks @Stephen Marsh ! 

I have to admit, this is (one) my Billy Madison moment(s). Because I create a new file in my script, it has no idea about the metadata.

 

For completion 

*OP now Goggling "how to copy metadata to a new file in Photoshop"

 

Cheers, Alex



You will find it much easier to duplicate the original file (retaining metadata) then modify it as needed to make it conform to a new document, without it actually being a new blank document (changing name, removing layers, changing canvas size etc).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 27, 2023 Jul 27, 2023

Thanks again! Indeed I could reduce the resolution and keep the file. But since this script is part of an action, creating a new document ensures that the size and dpi are correct for postcard printing. And pasting also gives me t he ability to invoke the move tool and place it interactively during the action.

 

I can sync the metadata in Lightroom easily. Copy pasting it is not doable by action and by scripting I got some hints. But Lighroom is here and done.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 27, 2023 Jul 27, 2023
LATEST

@alex.furer wrote:

Thanks again! Indeed I could reduce the resolution and keep the file. But since this script is part of an action, creating a new document ensures that the size and dpi are correct for postcard printing.



Duplicating the source doc, resizing, removing layers etc. also ensures that the size is correct, while maintaining metadata – without introducing any extra steps or dependencies into the workflow.

 

quote

But Lighroom is here and done.

 

It is obviously more long-winded and manual, but as long as you get the result that you are looking for I guess.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines