Skip to main content
AG_Ps_100
Inspiring
December 28, 2019
Answered

Delete Active Document - Recycle Bin

  • December 28, 2019
  • 2 replies
  • 1598 views

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();

 

This topic has been closed for replies.
Correct answer r-bin
Give it a try.
Works. Checked on win7.

 

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();

 

 

 

2 replies

r-binCorrect answer
Legend
December 28, 2019
Give it a try.
Works. Checked on win7.

 

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();

 

 

 

Kukurykus
Legend
December 29, 2019

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('\\\\') + '");'

 

Kukurykus
Legend
December 28, 2019

'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()