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

Save a copy of the document in Desktop

New Here ,
Aug 29, 2013 Aug 29, 2013

Hi

I am trying to use the saveAs function to just save the actual file in the my desktop.

but I do not want to convert anything.

the saveAs function ask for a saveOptions where we can configure the saveas options.

I  just want the openned file to be copied to my Desktop.

follow my actual code:

saveFile = new File( "~/Desktop/" + app.activeDocument.name)

saveOptions = new JPEGSaveOptions();

saveOptions.embedColorProfile = true;

saveOptions.formatOptions = FormatOptions.STANDARDBASELINE;

saveOptions.matte = MatteType.NONE;

saveOptions.quality = 5;

app.activeDocument.saveAs(saveFile, saveOptions, true,Extension.LOWERCASE);

But this code alter the actual file.

If i Open a tiff and use this script it will save a jpeg... I do not to change the opened file. Just copy it to my Desktop

Best Regards

TOPICS
Actions and scripting
1.1K
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 , Aug 29, 2013 Aug 29, 2013

You either need to determine the document's existing format and use the correct saveOptions for that format or make a reference to the existing file and use the File.copy() method to move it.

function getFormat(){

    var ref = new ActionReference();

    ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

    try{

        if(executeActionGet(ref).hasKey(stringIDToTypeID("format"))){

            return  executeActionGet(ref).getString(stringIDToTypeID("format"))

...
Translate
Adobe
Guru ,
Aug 29, 2013 Aug 29, 2013

You either need to determine the document's existing format and use the correct saveOptions for that format or make a reference to the existing file and use the File.copy() method to move it.

function getFormat(){

    var ref = new ActionReference();

    ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

    try{

        if(executeActionGet(ref).hasKey(stringIDToTypeID("format"))){

            return  executeActionGet(ref).getString(stringIDToTypeID("format"));

        }

    }catch(e){}

};

var saveFile = new File( "~/Desktop/" + app.activeDocument.name);

var docFormat = getFormat();

switch(docFormat){

    case 'Photoshop':

            // set photoshop saveOptions

            break;

    case 'TIFF':

            // set tif saveOptions

            break;        

    case 'JPEG':

            // set jpg saveOptions

            break;

    // add case statements for other formats you want to support

    default:

         // handle un-supported formats and newly created document

}

app.activeDocument.saveAs(saveFile, saveOptions, true,Extension.LOWERCASE);

function getDocPath(){

    var ref = new ActionReference();

    ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

    var desc = executeActionGet(ref);

    var res = desc.hasKey(stringIDToTypeID('fileReference')) ?  File(desc.getPath(stringIDToTypeID('fileReference'))).exists: false;

    return res ? File(desc.getPath(stringIDToTypeID('fileReference'))):false;

};

// may want to do a normal Document.save() to make sure file is current

var saveFile = new File( "~/Desktop/" + app.activeDocument.name);

var existingDocFile = getDocPath();

if( existingDocFile ){

    // use copy first

    existingDocFile.copy(saveFile);

    // uncomment if you want to 'move' the file

    //existingDocFile.remove();

}

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 ,
Aug 30, 2013 Aug 30, 2013
LATEST

Thanks!

It is exactaly what I need.

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