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

SAVE TIF of activeDocument and make activeDocument the TIF I've just saved

Engaged ,
May 25, 2019 May 25, 2019

Copy link to clipboard

Copied

Hello everyone,

I have this NEF file, and I want to save it as tif.

so I use this script:

#target photoshop  

var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');  

try

{

    var savePath = activeDocument.path;

catch(e)

{  

    alert("You must save this document first!\nTo establish a save path..."); 

    savePath = Folder.selectDialog("select folder");

}

var fileList= savePath.getFiles(Name +"*.tif").sort().reverse();  

var saveName = File(savePath + "/" + Name) 

SaveTIFF(saveName);    

   

   

////////////////////////////////////////////////////////////////////////////////////////////////// 

    function SaveTIFF(saveFile){ 

tiffSaveOptions = new TiffSaveOptions();  

tiffSaveOptions.embedColorProfile = true;  

tiffSaveOptions.alphaChannels = true;  

tiffSaveOptions.layers = true; 

tiffSaveOptions.imageCompression = TIFFEncoding.NONE; 

//tiffSaveOptions.jpegQuality=10; 

activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);  

}

After I save the file I do have the tif file in my folder, but I want that the activeDocument will be the tif file.

THIS IS WHAT I WANT:

I know that I can close the activeDocument and the open the tif file,

but in order to save time, I want the activeDocument will change like when you Save As in photoshop using Ctrl+Shift+S and afterwards the file changes from NEF to TIF automatically.

How do I do that please?

TOPICS
Actions and scripting

Views

2.6K

Translate

Translate

Report

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 , May 25, 2019 May 25, 2019

Try this (original post's code updated):

#target photoshop 

 

try 

    var savePath = activeDocument.path; 

}   

catch(e) 

{    

    alert("You must save this document first!\nTo establish a save path...");   

    savePath = Folder.selectDialog("select folder");  

}

 

var Name = app.activeDocument.name.replace(/\.[^\.]+$/, ''); 

 

save(); 

function save() { 

  var c2t = function (s) { 

  return app.charIDToTypeID(s); 

  }; 

 

  var s2t = function (s) { 

  return app.stringIDToTypeID(s); 

  }; 

...

Votes

Translate

Translate
Adobe
Community Expert ,
May 25, 2019 May 25, 2019

Copy link to clipboard

Copied

Try this (original post's code updated):

#target photoshop 

 

try 

    var savePath = activeDocument.path; 

}   

catch(e) 

{    

    alert("You must save this document first!\nTo establish a save path...");   

    savePath = Folder.selectDialog("select folder");  

}

 

var Name = app.activeDocument.name.replace(/\.[^\.]+$/, ''); 

 

save(); 

function save() { 

  var c2t = function (s) { 

  return app.charIDToTypeID(s); 

  }; 

 

  var s2t = function (s) { 

  return app.stringIDToTypeID(s); 

  }; 

 

  var descriptor = new ActionDescriptor(); 

  var descriptor2 = new ActionDescriptor(); 

 

  descriptor2.putEnumerated( s2t( "byteOrder" ), s2t( "platform" ), s2t( "macintosh" )); 

  descriptor.putObject( s2t( "as" ), c2t( "TIFF" ), descriptor2 ); 

  descriptor.putPath( c2t( "In  " ), new File(savePath + "/" + Name + ".tif") ); 

  descriptor.putInteger( s2t( "documentID" ), 813 ); 

  descriptor.putBoolean( s2t( "lowerCase" ), true ); 

  descriptor.putEnumerated( s2t( "saveStage" ), s2t( "saveStageType" ), s2t( "saveSucceeded" )); 

  executeAction( s2t( "save" ), descriptor, DialogModes.NO ); 

}

Votes

Translate

Translate

Report

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
Engaged ,
May 25, 2019 May 25, 2019

Copy link to clipboard

Copied

It works, thank you

It just occurred to me that the solution to that was easy I should have just used ScriptListener and then Save As, and then still use the savePath and Name, great job

Votes

Translate

Translate

Report

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
Guide ,
May 25, 2019 May 25, 2019

Copy link to clipboard

Copied

All you need to do is change the true to false.

  1.     function SaveTIFF(saveFile){   
  2. tiffSaveOptions = new TiffSaveOptions();    
  3. tiffSaveOptions.embedColorProfile = true;    
  4. tiffSaveOptions.alphaChannels = true;    
  5. tiffSaveOptions.layers = true;   
  6. tiffSaveOptions.imageCompression = TIFFEncoding.NONE;   
  7. //tiffSaveOptions.jpegQuality=10;   
  8. activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);    
  9. }

  1.     function SaveTIFF(saveFile){   
  2. tiffSaveOptions = new TiffSaveOptions();    
  3. tiffSaveOptions.embedColorProfile = true;    
  4. tiffSaveOptions.alphaChannels = true;    
  5. tiffSaveOptions.layers = true;   
  6. tiffSaveOptions.imageCompression = TIFFEncoding.NONE;   
  7. //tiffSaveOptions.jpegQuality=10;   
  8. activeDocument.saveAs(saveFile, tiffSaveOptions, false, Extension.LOWERCASE);     +
  9. }

The true means save as copy.

Votes

Translate

Translate

Report

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
Engaged ,
May 25, 2019 May 25, 2019

Copy link to clipboard

Copied

Even better. I've always preferred to not use ScriptListener.

On another issue, I wanted to know if there's a way to script these 2 Camera Raw's tools:

1. Transform Tool > Upright = Full

2. Straighten Tool Double Click = Auto-Straighten & Crop

Votes

Translate

Translate

Report

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
Guide ,
May 25, 2019 May 25, 2019

Copy link to clipboard

Copied

Camera Raw is not scriptable as such. The metadata can be altered but I think you are out of luck as it seems to do the transform calculations for the various metadata entries in ACR.

Votes

Translate

Translate

Report

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 ,
May 25, 2019 May 25, 2019

Copy link to clipboard

Copied

LATEST

Thanks SuperMerlin, 101 stuff huh! Note to self, study the code and compare to the manual before looking for alternatives...

Votes

Translate

Translate

Report

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 ,
May 25, 2019 May 25, 2019

Copy link to clipboard

Copied

If the activeDocument was opened from an existing images file not a RAW file. The Active Document has a backing files on disk. The files you opened.  The Active document name is read only it can not be changed by any Photoshop commend.   When the Active document is a new document. That is you open a new document or a RAW file the document in Photoshop has no backing file on disk for  Camera RAW files can not be written by Photoshop so the RAW file on disk does not count as a backing file. As far as Photoshop is concerned the document in Photoshop is a new document.   When you saved a new Document. The document in Photoshop is no longer a new document it now has a backing file one disk during the saving of the file Photoshop will fixes the Open Document name to the saved files name.  The Document name is fixed read only it can not be renames by a  and Photoshop command. A script or action can not rename and open document in Photoshop the has a backing file. It would need to do what you wrote. Open the file just saved and close the document is was saved from.

If you open a NEF file its a new document in  Photoshop when you save it as a Tif I would think the Photoshop would fix the document name in Photoshop to the saved file name.

JJMack

Votes

Translate

Translate

Report

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 ,
May 25, 2019 May 25, 2019

Copy link to clipboard

Copied

The Active document name is read only it can not be changed by any Photoshop commend.

Agreed, however it can be used in a variable for reference in the save (obviously not changing the name of the live open document):

var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');

When the Active document is a new document. That is you open a new document or a RAW file the document in Photoshop has no backing file on disk for  Camera RAW files can not be written by Photoshop so the RAW file on disk does not count as a backing file. As far as Photoshop is concerned the document in Photoshop is a new document.

This appears to work too, a path is reported in the alert test below when run on a raw camera file:

var filePath = activeDocument.path;

alert(filePath);

The try/catch in the full script does not error, it appears to accept that there is a valid backing path.

In my script the TIFF is saved to the same directory as the raw file, with the same name, just with a .tif extension and in TIFF format.

I have tested my script in CS6 and CC2018 with a raw camera file from disk that has been opened into Photoshop through ACR and it appears to do everything that the OP has requested. I used AM code as I could not get the save to work as intended with DOM code.

My original script duplicated the original doc and closed down the original doc, however with experimentation I found that I did not need to do this to achieve the desired outcome.

Votes

Translate

Translate

Report

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 ,
May 25, 2019 May 25, 2019

Copy link to clipboard

Copied

JJMack

Votes

Translate

Translate

Report

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