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

Photoshop Script for faster Save for Web

New Here ,
Nov 13, 2019 Nov 13, 2019

Copy link to clipboard

Copied

macOS Catalina really messed up my workflow with Save for Web, so I put together three scripts to be able to use it as fast as possible. 

 

You can edit the folder path in code (to use a default folder), save them as 'Fast Save.js' (or any name you like) to Applications > Photoshop > Preset > Scripts, and use them via File > Scripts menu. 

 

First one is Fast Save, it prompts for a file name, and saves for web in your 'default' folder.  It overwrites without a prompt, so be careful!

 

 

 

// Fast Save

//Save for Web Options
var sfwOptions = new ExportOptionsSaveForWeb();   
sfwOptions.format = SaveDocumentType.JPEG;   
sfwOptions.includeProfile = false;   
sfwOptions.interlaced = false;   
sfwOptions.optimized = true;   
sfwOptions.quality = 90;

// Folder
var saveFolder = new Folder('~/Desktop');

// Extension
var saveExt = 'jpg';

// Ask for name
var docName = prompt("File name", ""); 

// Save file
var saveFile = new File( saveFolder + '/' + docName + '.' + saveExt );

// Save for Web
activeDocument.exportDocument( saveFile, ExportType.SAVEFORWEB, sfwOptions );  

 

 

 

Second one is Quick Save, it prompts for a file name, and saves to your default folder with incremental suffix (filename_001.jpg)

 

 

 

// Quick Save

// Folder
var saveFolder = new Folder('~/Desktop');

// Suffix
var saveSufixStart = '_';
var saveSufixLength = 3;

// Extension
var saveExt = 'jpg';

// Save for Web Options
var sfwOptions = new ExportOptionsSaveForWeb();   
sfwOptions.format = SaveDocumentType.JPEG;   
sfwOptions.includeProfile = false;   
sfwOptions.interlaced = false;   
sfwOptions.optimized = true;   
sfwOptions.quality = 90;


// Zero(s) Function
function zeroPad ( num, digit ){
var tmp = num.toString();
while (tmp.length < digit) { tmp = "0" + tmp;}
return tmp;
}

// Ask for File Name
var docName = prompt("File name", "Default"); 

// Check other files with same name, and increment 
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] ,10) + 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 = parseInt( fileName[ 1 ].match( /_(\d{3})$/ )[1] ,10) + 1; // strip the ext and get the sufix , convert to number and add 1
}

// File Name
var saveFile = new File( saveFolder + '/' + saveName + '_' + zeroPad( saveNumber, saveSufixLength ) + '.' + saveExt );

// Save for Web
activeDocument.exportDocument( saveFile, ExportType.SAVEFORWEB, sfwOptions );  

 

 

 

and the last one, Quicker Save, uses a default file name (or uncomment line 33 to use the original filename) and saves for web to your default folder incrementally.

 

 

 

// Quicker Save

// Folder
var saveFolder = new Folder('~/Desktop');

// Suffix
var saveSufixStart = '_';
var saveSufixLength = 3;

// Extension
var saveExt = 'jpg';

// Save for Web Options
var sfwOptions = new ExportOptionsSaveForWeb();   
sfwOptions.format = SaveDocumentType.JPEG;   
sfwOptions.includeProfile = false;   
sfwOptions.interlaced = false;   
sfwOptions.optimized = true;   
sfwOptions.quality = 90;


// Zero(s) Function
function zeroPad ( num, digit ){
var tmp = num.toString();
while (tmp.length < digit) { tmp = "0" + tmp;}
return tmp;
}

// File name - Use a Default name for all
var docName = 'default';

// or uncomment below to use the actual filename
//var docName = decodeURI (activeDocument.name);

// Check other files with same name, and increment 
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] ,10) + 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 = parseInt( fileName[ 1 ].match( /_(\d{3})$/ )[1] ,10) + 1; // strip the ext and get the sufix , convert to number and add 1
}

// File Name
var saveFile = new File( saveFolder + '/' + saveName + '_' + zeroPad( saveNumber, saveSufixLength ) + '.' + saveExt );

// Save for Web
activeDocument.exportDocument( saveFile, ExportType.SAVEFORWEB, sfwOptions );  

 

 

 

 

Note: Incremental saving part was taken from https://community.adobe.com/t5/Photoshop/Incremental-quicksaving/td-p/9668383

TOPICS
Actions and scripting

Views

4.0K

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
no replies

Have something to add?

Join the conversation
Adobe