saving options

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

ch3

saving options

Post by ch3 »

Hello,
first post, first day into photoshop scripting.

To start off, I decided to attempt a scipt which will save the active document with a padded increment before the extension.
file.0000.jpg will be saved as file.0001.jpg and so on...

I managed to do the string manipulation, in a basic way (without any checks), but I was wondering about the saving options. At the moment, it will only save as jpg as I copied this chunk of code for one of the examples. Is there a way to query the options of the current file and use them directly to the saveAs function? or do I have to make multiple checks with different code for each different file format?

By the way, have a look to the current scipt and tell me if you see something which can be re-written in a better way.

thanx a lot.

Code: Select allvar doc = app.activeDocument;

var fileName = doc.name.toString();
var cleanName = fileName.substr( 0, fileName.lastIndexOf(".")-5 );
var extension = fileName.substring( fileName.lastIndexOf(".")+1 );
var frame = parseFloat( fileName.substr( fileName.lastIndexOf(".")-4, 4 ) );


var filePath = doc.fullName.toString();
var folder = filePath.substr( 0, filePath.lastIndexOf( "/" )+1 );


//alert( "fileName=" + fileName +"\nname="+cleanName+"\nframe="+frame+"\nextension="+extension+"\nfolder="+folder);



jpgFile = new File( folder + cleanName +"."+ padIt4(frame+1) +"."+ extension )

//taken from an example
jpgSaveOptions = new JPEGSaveOptions()
jpgSaveOptions.embedColorProfile = true
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE
jpgSaveOptions.matte = MatteType.NONE
jpgSaveOptions.quality = 1
app.activeDocument.saveAs(jpgFile, jpgSaveOptions, false, Extension.LOWERCASE)








function padIt4( inInt )
{
   var out = inInt.toString();
   
   while( out.length < 4 )
      out = "0" + out;
   
   return out;
}
ch3

saving options

Post by ch3 »

so you believe there isnt an easy way around it?
Andrew

saving options

Post by Andrew »

"Is there a way to query the options of the current file and use them directly to the saveAs function?"

I have never looked into this so can't help off the top of my head.

"By the way, have a look to the current scipt and tell me if you see something which can be re-written in a better way. "

That's a pretty broad question. Oneof the best ways to learn coding style is to look at other peoples code. Xbytor's code is the tightest I have seen but it is also hard to read sometimes. Mine is highly variable, getting better over time I hope.

Sorry not to be more help,

Andrew
ch3

saving options

Post by ch3 »

ok no worries
xbytor

saving options

Post by xbytor »

You can't query the SaveOptions of a saved file. Some options describe a transformation of the image (like JPEG Quality) that happens during a save that may or may not be useful when you reopen the image.

Other options, like compression mode in TIF, really don't matter all that much after the image is opened. They only matter when an image is going to be saved again and you want it to be in the identical file format as the original.

Unfortunately, that information doesn't appear to be cached anywhere for you to retrieve it.