Skip to main content
Parts4Arts
Inspiring
December 24, 2021
Answered

Save copy incrementally with javascript in Photoshop

  • December 24, 2021
  • 11 replies
  • 4565 views

The free Javascript "Save-Incrementally.jsx" for Adobe Illustrator 2022, Adobe Photoshop 2022 and Adobe InDesign 2022 or older versions saves the current saved document in the file format .ai, .psd or .indd and automatically adds a consecutive number to the file name. Thus, the file "Example.ai" becomes the file "Example-0001.ai", "Example-0002.ai" and so on; this works analogously for Photoshop and InDesign. This is also called "incremented" (continuous) saving. In this way, you can save individual steps in between and go back to an older version if necessary. The Javascript also works with older versions of Illustrator, Photoshop and InDesign.  

See my Behance profile or on my german website.

 

Have fun with it and merry christmas to all.

– jens

Correct answer Stephen Marsh

As it looks like @Parts4Arts is no longer active, you can download various versions of the scripts from my archive here:

 

https://www.dropbox.com/scl/fi/b1l8b03lqo5lz0g6exdrh/ai_ps_ind_Save-Incrementally.zip?rlkey=x7edz94n1ol4ho8gw6mhm9nyc&st=2glpr7cf&dl=0

 

There are other scripts on this forum to save incremental files, however they are only for Photoshop.

11 replies

Participating Frequently
February 5, 2025

Hi guys,

was looking for this kind of function for a while now and happy to find something that is quite a good base.

BUT I was wondering if this script could be re-scripted that it's actually saving the files like a real incremental save would do it, so version up your file and NOT adding a new version counter at the ending.

Is this even possible?

 

Thanks a lot,

Sandra

Stephen Marsh
Braniac
February 5, 2025

@SandraPL wrote:

Hi guys,

was looking for this kind of function for a while now and happy to find something that is quite a good base.

BUT I was wondering if this script could be re-scripted that it's actually saving the files like a real incremental save would do it, so version up your file and NOT adding a new version counter at the ending.

Is this even possible?

 

Thanks a lot,

Sandra


 

 

If I understand what I think you're requesting, then no.

 

Scripts can't change how Photoshop file formats work. So we can't make a single file with various version states hidden in the file from which we can pick from. As Photoshop isn't a database, we can't track revisions using BLOBs either.

 

If you meant something else, then please spell it out in more detail.

Participating Frequently
February 6, 2025

Hi @Stephen Marsh 

thanks for coming back on this request.

In detail: I would like to only version up e.g. from *_comp_v001 -> *_comp_v002.

The script is working instead like this *_comp_v001 -> *_comp_v001-0000.

 

Thanks,

Sandra

Stephen Marsh
Stephen MarshCorrect answer
Braniac
September 12, 2024

As it looks like @Parts4Arts is no longer active, you can download various versions of the scripts from my archive here:

 

https://www.dropbox.com/scl/fi/b1l8b03lqo5lz0g6exdrh/ai_ps_ind_Save-Incrementally.zip?rlkey=x7edz94n1ol4ho8gw6mhm9nyc&st=2glpr7cf&dl=0

 

There are other scripts on this forum to save incremental files, however they are only for Photoshop.

Stephen Marsh
Braniac
September 12, 2024

Links to some of the alternative incremental scripts:

 

 

 
 
 
 
 
#target photoshop

main();

function main() {
    if (!documents.length) return;
    var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
    try {
        var savePath = activeDocument.path;
    } catch (e) {
        alert("You must save this document first!");
    }
    var fileList = savePath.getFiles("*.jpg").sort().reverse();
    var Suffix = 0;
    if (fileList.length) {
        Suffix = Number(fileList[0].name.replace(/\.[^\.]+$/, '').match(/\d+$/));
    }
    Suffix = zeroPad(Suffix + 1, 3);
    //var saveFile = File(savePath + "/" + Name + "_" + Suffix + ".jpg");
    var saveFile = File(savePath + "/" + Suffix + ".jpg");
    SaveJPEG(saveFile, 8); // JPEG compression level
}

function SaveJPEG(saveFile, jpegQuality) {
    jpgSaveOptions = new JPEGSaveOptions();
    jpgSaveOptions.embedColorProfile = true;
    jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
    jpgSaveOptions.matte = MatteType.NONE;
    jpgSaveOptions.quality = jpegQuality;
    activeDocument.saveAs(saveFile, jpgSaveOptions, true, Extension.LOWERCASE);
}

function zeroPad(n, s) {
    n = n.toString();
    while (n.length < s) n = '0' + n;
    return n;
}

 

// Save PNG next to PSD (Incremental numbers).jsx

#target photoshop

var savePSD    = false; // If set true the psd document is saved every time the script runs...
var folderName = ' (Frames)';

try {

  var doc   = app.activeDocument;
	var fileExists = false;
	
	try { if ( savePSD ) doc.save(); } catch(e){}
	
	try {
		fileExists = doc.path;
	}
	catch(e){
		var idsave = charIDToTypeID( "save" );
		var desc50 = new ActionDescriptor();
		var idIn = charIDToTypeID( "In  " );
		desc50.putPath( idIn, new File( Folder.desktop.fullName ) );
		var idDocI = charIDToTypeID( "DocI" );
		desc50.putInteger( idDocI, 196 );
		var idsaveStage = stringIDToTypeID( "saveStage" );
		var idsaveStageType = stringIDToTypeID( "saveStageType" );
		var idsaveSucceeded = stringIDToTypeID( "saveSucceeded" );
		desc50.putEnumerated( idsaveStage, idsaveStageType, idsaveSucceeded );
		executeAction( idsave, desc50, DialogModes.ALL );
		fileExists = doc.path;
	}
	
	if ( fileExists ) {
		saveNewVersion( doc );
	}

}
catch( e ) {
  // remove comments below to see error for debugging
  // alert( e );
}

function saveNewVersion( doc, docName ) {

  var extension 	= '.png';
  var docName     = doc.name.substring(0, doc.name.lastIndexOf('.'));
  var docPath     = doc.path;
	
  var outputPath = docPath + '/' + doc.name + folderName;
	
  var outputFolder = new Folder( outputPath );
  if( !outputFolder.exists ) { outputFolder.create(); }
	
  var verisonsList = outputFolder.getFiles( '*' + extension );
	var versionsLength1 = verisonsList.length;
	var number = getVersionNumber( docName, verisonsList );
	
	var filename = number + extension;
	doc.exportDocument( File( outputPath + '/' + filename ), ExportType.SAVEFORWEB, exportOptions() );
  app.beep();

}

function getVersionNumber( docName, verisonsList ) {
	
	var number = 0;
	for ( var i = 0; i < verisonsList.length; i++ ) {
		
		var file = verisonsList[i];
		var fileName = File(file).displayName;
		fileName = fileName.substring(0, fileName.lastIndexOf('.'));
		
		// Start looking for the version number if PSD filename contains doc name...
		var versionNumber = fileName.match(/^[0-9]*/);
		
		if ( versionNumber ) {
			versionNumber = parseInt( versionNumber ,10);
			if ( number < versionNumber ) {
				number = versionNumber;
			}
		}
		
	}
	
	return number + 1;
	
}

function exportOptions() {
	
	var options = new ExportOptionsSaveForWeb();
	
	options.format = SaveDocumentType.PNG;
	options.quality = 100;
	
	return options;
	
}
Stephen Marsh
Braniac
September 10, 2024

@Parts4Arts 

 

Are you still out there?

New Participant
January 4, 2024

bro, your link not working.

Participating Frequently
May 28, 2022

Also... I'm trying to use 'date and time' instead of the counter option to prevent it from overwriting the previous save, but everytime I try to save it it just tries to save a psd. Tif works fine but I need png.

Participating Frequently
May 28, 2022

This sounds great, but when I use it to save an incremented png it just overwrites the previous png. Any ideas?

gener7
Braniac
December 30, 2021

Thanks for providing the script. Firefox threw up this error:

 

I don't think it's  serious, but the download link is:

http://www.computergrafik-know-how.de/wp-content/uploads/2021/12/A117-2D-AI-JS-Save.zip

 

I guess it thinks http instead of https is a risk.

Kukurykus
Braniac
December 30, 2021

If you right click a link to open it in new card instead of tab, does the download start without warning?

gener7
Braniac
December 30, 2021

My browser doesn't have a "new card", unless you mean "new window", and yes I get the warning there. I click on "Allow download"  anyway because the warning seems to be over a non-https connection.

Parts4Arts
Inspiring
December 30, 2021

Update Version 1.7: Saves the sequentially numbered copy in the same file format as the working file like psd, psb, bmp, eps, gif, jpg, pdf, png, raw, tga or tif in Photoshop.

 

See my Behance profile or on my german website.

Geppetto Luis
Braniac
December 29, 2021

I did not understand how to download the file, you can put links on the forum

Parts4Arts
Inspiring
December 29, 2021

Hello Geppetto,

click on this link to go to my behance post.

Read the text and scoll down, to dowload the .zip-file.

– jens

Parts4Arts
Inspiring
December 29, 2021

The new version 1.5 saves the original document in Illustrator and InDesign. The copy with the sequential number is created faster by the operating system.
– jens.