Copy link to clipboard
Copied
Hi friends! I need help getting a working script to create and move the open document to a sub folder called "Processed Image" I have this script but the current document has not been moved to the sub folder. Where is the error? Thank you
#target photoshop
app.bringToFront();
var docRef = app.activeDocument;
var sourceFolder = app.activeDocument.path ;
var File1 = docRef;
var tempFile = File1;
tempFile = tempFile.File1;
var outputFolder = new Folder(File1.path + "/Processed Image"); // defines the name of the subfolder
//Check if it exist, if not create it.
if(!outputFolder.exists) outputFolder.create(); //if subfolder not exist then create
if(tempFile != null){
var saveName = tempFile.name;
var res = tempFile.copy(new File(outputFolder+'/'+saveName));
if(res != true) throw('Unable to move file to '+decodeURI(backupFolder));
res = tempFile.copy(new File(outputFolder+'/'+saveName));
if(res != true){
throw('Unabe to move file to '+decodeURI(outputFolder));
}else{
// if we get here then the file has been backuped and moved to new folder so delete
tempFile.remove();
app.open(new File(outputFolder+'/'+saveName));// open moved file to work on
}
}
Try this:
...#target photoshop
app.bringToFront();
var docRef = app.activeDocument;
var sourceFolder = app.activeDocument.path ;
var res
var File1 = docRef;
var outputFolder = new Folder(File1.path + "/Processed Image"); // defines the name of the subfolder
var tempFile = new File(docRef.path +'/'+docRef.name)
//Check if it exist, if not create it.
if(!outputFolder.exists) outputFolder.create(); //if subfolder not exist then create
if(tempFile.exists){
var saveName = tempFile.name;
Copy link to clipboard
Copied
Try this:
#target photoshop
app.bringToFront();
var docRef = app.activeDocument;
var sourceFolder = app.activeDocument.path ;
var res
var File1 = docRef;
var outputFolder = new Folder(File1.path + "/Processed Image"); // defines the name of the subfolder
var tempFile = new File(docRef.path +'/'+docRef.name)
//Check if it exist, if not create it.
if(!outputFolder.exists) outputFolder.create(); //if subfolder not exist then create
if(tempFile.exists){
var saveName = tempFile.name;
tempFile.copy(outputFolder+'/'+saveName);
res = new File(outputFolder+'/'+saveName)
if(!res.exists) {throw('Unable to move file to '+decodeURI(outputFolder));
}
else{
// if we get here then the file has been backuped and moved to new folder so delete
tempFile.remove();
app.open(res);// open moved file to work on
}
}
Copy link to clipboard
Copied
I have a question regarding the line
var res
It seems to work fine but I was wondering, don't you have to at least put something after the variable like
var res = ""
Is is good enought to declare a variable as simply a name as shown here?
Copy link to clipboard
Copied
No, you don't need to put anything. That can be done later, when you actually have something to assign the variable. You can do that if you want to define what type of variable it is, like string, boolean, array, etc.
Copy link to clipboard
Copied
Thank you Chuck!
Copy link to clipboard
Copied
Alternatively you may use: res = undefined
Copy link to clipboard
Copied
Cheers Kukurykus!
Copy link to clipboard
Copied
instead of this
var tempFile = File1; | |
tempFile = tempFile.File1; |
use
var tempFile = File1.fullName;
Copy link to clipboard
Copied
It works divinely well! I tested the modification made by Chuck Uebele and the suggestion of the r-bin and both worked perfectly. Many thanks to both friends.