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

PS Script : Incremental save

Community Beginner ,
Sep 09, 2020 Sep 09, 2020

Copy link to clipboard

Copied

Hello,

I have this script which saves my open document as the file name, + an increment.

 

Works great but..it currently saves in a specified directory.
Is it possible to modify this to save the document in its current directory?
Thanks for any help!
Jeff

    
#target photoshop

// This script will save the active document to a folder with an incremental sufix
    // Change the options below to match your needs
    var saveFolder = new Folder( 'C:/Storyboards/Projects01' );
    var saveExt = 'psd';
    var saveSufixStart = '_';
    var saveSufixLength = 3;
    psdOpts = new PhotoshopSaveOptions();
    psdOpts.embedColorProfile = true;
    psdOpts.alphaChannels = true;
    psdOpts.layers = true;
    // End of user options
    //==========================================
    function zeroPad ( num, digit ){
       var tmp = num.toString();
       while (tmp.length < digit) { tmp = "0" + tmp;}
       return tmp;
    }
    var docName = decodeURI ( activeDocument.name );
    docName = docName.match( /(.*)(\.[^\.]+)/ ) ? docName = docName.match( /(.*)(\.[^\.]+)/ ) : docName = [ docName, docName, undefined ];
    var saveName = docName[ 1 ]; // activeDocument name with out ext
    var files = saveFolder.getFiles( saveName + '*.' + saveExt );// get an array of files matching doc name prefix

    if( files.length == 0 ) {  // no file with that name so start at one
       var saveNumber = 1;
    }
    if( files.length == 1 ) { // one file found, see if it has a sufix
       var fileName = decodeURI ( files[ 0 ].name );
       fileName = fileName.match( /(.*)(\.[^\.]+)/ ) ? fileName = fileName.match( /(.*)(\.[^\.]+)/ ) : fileName = [ fileName, fileName, undefined ];
       if( fileName[1].match( /_(\d{3})$/ ) == null ){
          var saveNumber = 1;// does not have sufix so set to one
       } else{// has sufix
          var saveNumber = parseInt( fileName[ 1 ].match( /_(\d{3})$/ )[1] ) + 1; // strip the ext and get the sufix , convert to number and add 1
       }
    }
    if( files.length > 1 ){
       files.sort();
       var fileName = decodeURI ( files[ files.length -1 ].name );
       fileName = fileName.match( /(.*)(\.[^\.]+)/ ) ? fileName = fileName.match( /(.*)(\.[^\.]+)/ ) : fileName = [ fileName, fileName, undefined ];
       var saveNumber = Number( fileName[ 1 ].match( /_(\d{3})$/ )[1] ) + 1; // strip the ext and get the sufix , convert to number and add 1
    }
    var saveFile = new File( saveFolder + '/' + saveName + saveSufixStart + zeroPad( saveNumber, saveSufixLength ) + '.' + saveExt );
    activeDocument.saveAs( saveFile, psdOpts ,true ,Extension.LOWERCASE);

 

 

TOPICS
Actions and scripting

Views

724

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 , Sep 09, 2020 Sep 09, 2020

Change the following line

 

var saveFolder = new Folder( 'C:/Storyboards/Projects01' );

 

To

 

if(!app.documents[0].saved)
{
  CAlert("Please save the file before execution")
  exit()
}
var saveFolder = new Folder(app.activeDocument.fullName.parent)

 

-Manan

Votes

Translate

Translate
Adobe
Community Expert ,
Sep 09, 2020 Sep 09, 2020

Copy link to clipboard

Copied

Change the following line

 

var saveFolder = new Folder( 'C:/Storyboards/Projects01' );

 

To

 

if(!app.documents[0].saved)
{
  CAlert("Please save the file before execution")
  exit()
}
var saveFolder = new Folder(app.activeDocument.fullName.parent)

 

-Manan

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 Beginner ,
Sep 10, 2020 Sep 10, 2020

Copy link to clipboard

Copied

Works Great!

 

Many thanks,  Manan

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
Explorer ,
Sep 29, 2022 Sep 29, 2022

Copy link to clipboard

Copied

Hello, I would love to have this script, from you, can you please share the script with me, and the guide for installation? 

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 ,
Sep 29, 2022 Sep 29, 2022

Copy link to clipboard

Copied

LATEST
quote

Hello, I would love to have this script, from you, can you please share the script with me, and the guide for installation? 


By @Azmaeen Adil Sami

 

The original script code was shared by @Jeff S GP2 and the modification was posted by @Manan Joshi 

 

Instructions for saving and use here:

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

 

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