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

automate save as or export with sequential file names

Community Beginner ,
Apr 22, 2017 Apr 22, 2017

Copy link to clipboard

Copied

Hi, I have a script that does some basic color manipulates within a selection.  I will run this script thousands of times to produce my graphic.  I would like to export a copy of my working file each time I run this script so that I can compile each step into an animation.  Naming the files manually each time the action is run would be really tedious and time consuming.

I've been reading about batch actions and integrating those file naming options, but I seem to be going in circles without any results.  Could someone point me in the right direction please?

Views

9.1K

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 , Apr 22, 2017 Apr 22, 2017

Check out this thread: Progressive Save As New Jpeg

Votes

Translate

Translate
Adobe
Community Expert ,
Jan 18, 2021 Jan 18, 2021

Copy link to clipboard

Copied

// Save PNG next to PSD (Incremental numbers)

#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;
	
}

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 ,
Jan 18, 2021 Jan 18, 2021

Copy link to clipboard

Copied

This one does the job like I want, just that it saves the pictures in .PNG

How can I change it to jpeg with quality 12?

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 ,
Jan 18, 2021 Jan 18, 2021

Copy link to clipboard

Copied

That one is for both PSD and PNG versions.

 

I presume that this would just be a case of removing the PSD option and swapping out PNG for JPEG?

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 ,
Jan 18, 2021 Jan 18, 2021

Copy link to clipboard

Copied

I guess, I just have to replace PSD and PNG with JPEG?

It doesn't look that simple when I read the script

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 ,
Jan 18, 2021 Jan 18, 2021

Copy link to clipboard

Copied

I replaced 2 instances of "png" with "jpeg" and it is working 🙂

Thanks for all your help! 

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 ,
Jan 18, 2021 Jan 18, 2021

Copy link to clipboard

Copied

LATEST

It shouldn't be that simple!

 

You likely have a PNG format image with a JPG filename extension, which is not the same thing...

 

 

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 ,
Jan 18, 2021 Jan 18, 2021

Copy link to clipboard

Copied

// https://forums.adobe.com/message/4453915#4453915
#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(Name +"*.psd").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 + ".psd");
SavePSD(saveFile);
}
function SavePSD(saveFile){   
// http://jongware.mit.edu/pscs5js_html/psjscs5/pc_PhotoshopSaveOptions.html
psdSaveOptions = new PhotoshopSaveOptions();   
psdSaveOptions.embedColorProfile = true;   
psdSaveOptions.alphaChannels = true;    
psdSaveOptions.layers = true;
psdSaveOptions.annotations = true;
psdSaveOptions.spotColors = true;
activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);   
}; 
function zeroPad(n, s) { 
   n = n.toString(); 
   while (n.length < s)  n = '0' + n; 
   return n; 
};

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