Copy link to clipboard
Copied
Hello everyone,
I'm running windows 10 and I have this small script to delete active document. This script is irreversible the file is being deleted for good. Is there a way to upgrade the script to send it to the recycle bin ?
Here is my code:
#target photoshop
var FullPath = app.activeDocument.path.fsName;
var Name = app.activeDocument.name;
var myFile = new File(FullPath + "\\" + Name);
myFile.remove();
var FullPath = app.activeDocument.path.fsName;
var Name = app.activeDocument.name;
var p = (FullPath + "\\" + Name).toSource();
p = p.replace(/^\(new String\(/, "");
p = p.replace(/\)\)$/, "");
var js = new File(Folder.temp.fsName + "/tmp.js");
js.open("w");
js.encoding = "UTF8";
js.writeln('(new ActiveXObject("shell.application")).NameSpace(10).MoveHere(' + p + ');');
js.close();
js.execute();
Copy link to clipboard
Copied
'It deletes the file associated with this object from disk, immediately, without moving it to the system
trash. It cannot be undone. It is recommended that you prompt the user for permission before deleting.'
The above is taken from 'JAVASCRIPT TOOLS GUIDE'. I suggest to try with system()
Copy link to clipboard
Copied
var FullPath = app.activeDocument.path.fsName;
var Name = app.activeDocument.name;
var p = (FullPath + "\\" + Name).toSource();
p = p.replace(/^\(new String\(/, "");
p = p.replace(/\)\)$/, "");
var js = new File(Folder.temp.fsName + "/tmp.js");
js.open("w");
js.encoding = "UTF8";
js.writeln('(new ActiveXObject("shell.application")).NameSpace(10).MoveHere(' + p + ');');
js.close();
js.execute();
Copy link to clipboard
Copied
You may also instead of first 5(6) lines use this code:
'"' + activeDocument.fullName.fsName.split('\\').join('\\\\') + '"'
or directly instead of p variable, just with double quotation marks:
cde = '(new ActiveXObject("shell.application")).NameSpace(10).MoveHere'
cde += '("' + activeDocument.fullName.fsName.split('\\').join('\\\\') + '");'
Copy link to clipboard
Copied
once again @r-bin, thank you. it wokred.