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

adding suffix to file name and re-saving

New Here ,
Jul 17, 2009 Jul 17, 2009

I need a simple script that saves the open file as a jpeg at 80% compression to the same directory as the original, while adding a suffix to the end of the file name.  So for instance, if the file open is "image.png", I'd like it saved as "image_thumb.jpg".  I've tried to create my own, but I just don't have the chops for scripting.  Can anyone help?

TOPICS
Actions and scripting
3.7K
Translate
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

Guru , Jul 21, 2009 Jul 21, 2009

Replace the line

var docPath =Folder("~/Desktop");

with

var docPath = decodeURI(activeDocument.path);

Translate
Adobe
Advisor ,
Jul 17, 2009 Jul 17, 2009

This would be a good start:

http://ps-scripts.com/bb/viewtopic.php?t=2772

Translate
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
New Here ,
Jul 20, 2009 Jul 20, 2009

Thanks xbytor2, but unfortunately I'm still having problems with it. I amended the script to set the "docPath" just to "~/Desktop" instead of "~/Desktop/cropped" and I then I get the following script alert:

Unknown filetype please use manual save.

Not exactly sure why it's doing that.  Any help would be appreciated.

Translate
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
New Here ,
Jul 20, 2009 Jul 20, 2009

I've taken the script mentioned above and modified it to the best of my abilities.  Still getting the same error, unfortunately:

function main(){
/////////////////////////////////////////////////////////////////////////////////////////
var suffix ="cropped";
var docPath =Folder("~/Desktop");
//////////////////////////////////////////////////////////////////////////////////////////
if(!docPath.exists){
   alert(docPath + " does not exist!\n Please create it!");
   return;
   }
var fileName =activeDocument.name.match(/(.*)\.[^\.]+$/)[1];
var fileExt =activeDocument.name.toLowerCase().match(/[^\.]+$/).toString();
var saveFile = new File(docPath +"/"+fileName+suffix+'.'+fileExt);

switch (fileExt){
   case 'jpeg' : SaveJPEG(saveFile); break;
   default : alert("Unknown filetype please use manual save!"); break;
   }
}
if(documents.length) main();

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

Translate
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
Guru ,
Jul 20, 2009 Jul 20, 2009

My guess is that your document does not have the ext of 'jpeg'. The script below will save the doc as a jpg no matter what the ext.

function main(){
//////////////////////////////////////////////////////////////////////////////// /////////
var suffix ="_thumb";
var docPath =Folder("~/Desktop");
//////////////////////////////////////////////////////////////////////////////// //////////
if(!docPath.exists){
   alert(docPath + " does not exist!\n Please create it!");
   return;
   }
var fileName =activeDocument.name.match(/(.*)\.[^\.]+$/)[1];
var saveFile = new File(docPath +"/"+fileName+suffix+'.jpg');
SaveJPEG(saveFile);

}
if(documents.length) main();

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

Translate
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
New Here ,
Jul 21, 2009 Jul 21, 2009

Hm, it almost gets through it, but hangs on the last line.  The error states:


Error 1224: Numeric value expected

Line: 23

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

Translate
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
Guru ,
Jul 21, 2009 Jul 21, 2009

In the JPEGSaveOptions you need to set the quality to a value between 1 and 12

Translate
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
New Here ,
Jul 21, 2009 Jul 21, 2009

Ah, works great!  I'm sure you can see now how little experience I have with scripting.  I've marked this answered, but what would I have to change to have the file saved to the same folder as the original?

I found this, but I'm not sure how to use it.

Translate
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
Guru ,
Jul 21, 2009 Jul 21, 2009
LATEST

Replace the line

var docPath =Folder("~/Desktop");

with

var docPath = decodeURI(activeDocument.path);

Translate
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