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);
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
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
Copy link to clipboard
Copied
Works Great!
Many thanks, Manan
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?
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?
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