🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.photoshop.scripting
Article #323

Re: How to create action that saves file with modified filename?

#323
From: Paul_R
Date: Fri, 06 Feb 2009 11:28
108 lines
2802 bytes
Here you are, this should do the job.
Change the quality setting to suit your needs.
If the document is a new document that has not been saved it will be saved on the desktop.
If the file exists it will be renamed with a suffix of the time.


 
#target photoshop 

/// amend JPGquailty to suit can be 1 - 12. 

var JPGquality = 8;  

///////////////////////////////////////////////////////////////////////// 

if(documents.length){ 

var docPath=''; 

var docName=''; 

try{ 

   docName = activeDocument.name; 

   docPath =activeDocument.path; 

   }catch(e){  

      docPath = new Folder("~/desktop"); 

      docName = activeDocument.name + '.jpg'; 

      } 

var docNAME = docName.split('.'); 

var saveFile = new File(docPath+'/'+docNAME[0]+'.jpg'); 

var tmpFile = new File(docPath+'/'+docNAME[0]+'.jpg'); 

var renameFile = new File(docPath+'/'+docNAME[0]+time()+'.jpg'); 

if(tmpFile.exists) tmpFile.rename(renameFile); 

SaveJPEG(saveFile, JPGquality) 

} 

 

function time(){ 

var date = new Date(); 

   var d  = date.getDate(); 

   var day = (d < 10) ? '0' + d : d; 

   var m = date.getMonth() + 1; 

   var month = (m < 10) ? '0' + m : m; 

   var yy = date.getYear(); 

   var year = (yy < 1000) ? yy + 1900 : yy; 

   var digital = new Date(); 

   var hours = digital.getHours(); 

   var minutes = digital.getMinutes(); 

   var seconds = digital.getSeconds(); 

   var amOrPm = "AM"; 

   if (hours > 11) amOrPm = "PM"; 

   if (hours > 12) hours = hours - 12; 

   if (hours == 0) hours = 12; 

   if (minutes <= 9) minutes = "0" + minutes; 

   if (seconds <= 9) seconds = "0" + seconds; 

   todaysDate = "-" + hours + "_" + minutes + "_" + seconds + amOrPm; 

   return todaysDate.toString(); 

}; 

function SaveJPEG(saveFile, jpegQuality){ 

jpgSaveOptions = new JPEGSaveOptions(); 

jpgSaveOptions.embedColorProfile = true; 

jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE; 

jpgSaveOptions.matte = MatteType.NONE; 

jpgSaveOptions.quality = jpegQuality; //1-12 

activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE); 

}
Technical Details
Message-ID: <59b65848.2@webcrossing.la2eafNXanI>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!newshub.sdsu.edu!webcrossing
References: <59b65848.-1@webcrossing.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Thread: f5839,cdcad953af949bf0
X-Google-Attributes: gidf5839,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: Paul_R@adobeforums.com
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!newshub.sdsu.edu!webcrossing
Newsgroups: adobe.photoshop.scripting
Subject: Re: How to create action that saves file with modified filename?
Message-ID: <59b65848.2@webcrossing.la2eafNXanI>
Date: Fri, 6 Feb 2009 03:28:36 -0800
References: <59b65848.-1@webcrossing.la2eafNXanI>
Lines: 62
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit