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
Community Expert
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
Community Expert
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
Community Expert
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
Community Expert
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
Community Expert
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.

Parts4Arts
Inspiring
January 7, 2022

Update to version 2.0 with more features and user interface. Here the example from in Photoshop.

See my Behance profile or on my german website.

 

Parts4Arts
Inspiring
January 10, 2022
// Step 0d: Check if work file is saved
try { 
	var vFullName = ""+vDocRef.fullName; // Trick to convert to string
	var vPos = vFullName.lastIndexOf(vSeparator);
	vWorkPath = vFullName.substring(0,vPos);
	if (vFullName.charAt(0) == vSeparator) { vError = aMsg[[3,cLanguage]];} // stop, if document is unsaved, for AI
	}
catch (e) {vError = aMsg[[3,cLanguage]];} // for Photoshop

Check it in Photoshop. Condition vFullName.charAt(0) == vSeparator is always true for saved files


Hello jazz-y,

thanks for your answer.

If you use Photoshop, than you will get – without 'try' – the error 8103 if the work file was'nt saved before.

If you use Illustrator, than the condition 'vFullName.charAt(0) == vSeparator' is only true, when the file is not saved on the local harddisk. If so the path will begin with '~' like '~/Desktop'.

 

I have extended the programming. Now in version 2.1 you can also save copies to external hard drives or network drives.
Another new feature is that if you click on "Path for copy" and then on "Cancel" in the next window, the path for copy is reset and the copy is saved in the same directory (again) as the working file.

 

see https://www.behance.net/gallery/133799381/Javascript-for-AI-PS-ID-Save-with-automatic-numbering

 

Best regards,

– j.

 

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
Brainiac
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.