Copy link to clipboard
Copied
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
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"))
Copy link to clipboard
Copied
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();
}
Copy link to clipboard
Copied
Thanks!
It is exactaly what I need.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now