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

Getting SaveFileOptions from existing file?

Advocate ,
Mar 02, 2017 Mar 02, 2017

Copy link to clipboard

Copied

If I have a document, and I want to save it using an existing file's settings (whether the file is a TIFF, PSD, EPS, etc.)?

I have a few scenarios where I need to do this. In one case, I have a file that I need to save out multiple versions, and when I call document.saveAs without a saveOptions object, then it is saved as a PSD file, not the file type of the original file. In this instance, I could duplicate the current file, open that and just do a document.save and that should keep the original file type/options, but it would also require opening and saving the same file multiple times, and some of these files could be very large. I would much rather open the original document once, and save out the different versions from the original source file.

Another scenario, I will have a file that needs to be saved out as several different file formats, to match existing files. These files may be different file types, and I need to identify what the file types are, and what options were used to save those files, to match the existing files. In these instances, duplicating the current file won't work, as it would be saved as the current file type, not the existing file. I could probably duplicate the existing file, move the current file's content into the existing file, and save that, but that seems a bit too kludgy, and I'd prefer a cleaner solution, if possible.

I don't see any way to create the proper object to use in the document.saveAs method, so I'm not sure this is possible, but I was hoping that someone could clarify this, and hopefully let me know a way to complete this task properly and efficiently.

Thanks.

TOPICS
Actions and scripting

Views

267

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
Adobe
Community Expert ,
Mar 03, 2017 Mar 03, 2017

Copy link to clipboard

Copied

At least some of the properties can be assessed, see

is this possible to get EPS save encoding (ie.. BINARY, ASCII, ASCII85)

for eps, but apart from that to is not impossible in principle I cannot tell you much on this.

And this one concerning jpg quality was posted by Paul Riggot (as far as I can tell) a while back on ps-scripts.com

var file = File.openDialog("Please select JPG file.","JPG File:*.jpg");

main(file);

function main(file){

file.open("r");

file.encoding = 'BINARY';

filestring = file.read();

file.close();

var count = filestring.search(/\xFF\xEC/);

if(count > 200) count = -1;

if(count != -1){//Yes it is Save ForWeb

count += 16;  

var Quality = filestring[count].charCodeAt (0);

alert(decodeURI(file.name)+ " Save For Web, Quality " + Quality);

return;

}

count = filestring.search(/\xFF\xE1/);

if(count != -1){

filestring = filestring.substring(count+10);

count = filestring.search(/\xFF\xE1/);

}

if(count == -1) {//This file has not been edited with Photoshop!

  alert(decodeURI(file.name)+" has not been edited/saved with Photoshop!");

  return;

  }

count -= 8;

var Result = 0;

var FormatType = 0;

if(filestring[count] == 0) {

  }else{

  Result = filestring[count].charCodeAt (0);

  }

count++;

if(filestring[count] == 0) {

  }else{

  Result += filestring[count].charCodeAt (0);

  }

count++;

if(filestring[count] == 0) {

  }else{

  FormatType += filestring[count].charCodeAt (0);

  }

count++;

if(filestring[count] == 0) {

  }else{

  FormatType += filestring[count].charCodeAt (0);

  }

var Format =''

switch(FormatType){

  case 0: Format = " Format Standard";

  break;

  case 1: Format = " Format Optimised";

  break;

  case 2: Format = " Format Progressive";

  break;

  default:break;

  }

var Qualities = [507,508,509,510,0,1,2,3,4,5,6,7,8];

for(var a =0;a<Qualities.length;a++){

  if(Result == Qualities){

  alert(decodeURI(file.name)+" Save As, Quality " + a + Format);

  return;

  }

  }

}

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
Advocate ,
Mar 03, 2017 Mar 03, 2017

Copy link to clipboard

Copied

LATEST

Thanks, I will look into this. The majority of the files should be either EPS, TIFF, PSD or PSB files, although I may need to do Jpegs and/or PNGs in very rare circumstances.

If I can't get all of the properties from the existing file, and I can identify the type at least, I may be able to get away with creating a standard default setting for each file type, or for the settings that are not obtainable.

Thanks again, hopefully this will point me in the right direction.

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