Skip to main content
Paweł R.
Participating Frequently
May 30, 2023
Answered

Script save as tif with suffix

  • May 30, 2023
  • 1 reply
  • 1379 views

Please help me write a photoshop script.

 

First script:
i want to save the currently open tif file with the same name and add the "a" suffix.
Example:
123.tif > 123a.tif

 

Second script:
I want to save the currently open tif file with a rename that removes the last three characters.
Example:
123abc.tif > 123.tif

This topic has been closed for replies.
Correct answer c.pfaffenbichler

I want to remove the characters from the name from "_" to the end of the name


Try 

 

basename = basename.slice(0, basename.indexOf("_"));

 

1 reply

c.pfaffenbichler
Community Expert
Community Expert
May 31, 2023
// 2023, use at your own risk; 
if (app.documents.length > 0) {
    // get properties, thanks to xbytor;
    var myDocument = app.activeDocument;
    var docName = myDocument.name;
    var basename = docName.match(/(.*)\.[^\.]+$/)[1];
    try {var docPath = myDocument.path}
    catch (e) {var docPath = "~/Desktop"};
    saveAsTif (myDocument, docPath+"/"+basename+"a"+".tif")
    };
////// save tif //////
function saveAsTif (myDocument, thePath) {
// tif options;
tifOpts = new TiffSaveOptions();
tifOpts.embedColorProfile = true;
tifOpts.imageCompression = TIFFEncoding.TIFFLZW;
tifOpts.alphaChannels = false;
tifOpts.byteOrder = ByteOrder.MACOS;
tifOpts.layers = false;
// save as tif;
myDocument.saveAs((new File(thePath)), tifOpts, false);
};
Paweł R.
Paweł R.Author
Participating Frequently
May 31, 2023

error 24:

line9: saveAsTif  - is not a function  

Paweł R.
Paweł R.Author
Participating Frequently
May 31, 2023

basename.replace("_1a", "")


Great, thank you, it works