Skip navigation
Currently Being Moderated

CS5: delete current file within PS?

Sep 27, 2011 2:46 PM

Hello,

 

is it possible for a script (maybe via Bridge) to delete the current opened file?

 

thanks.

Carlos

 
Replies
  • Currently Being Moderated
    Sep 27, 2011 11:36 PM   in reply to cmeira

    I think this practice would be risky as there is no indo, but you could try this:

    #target photoshop
    var theString = app.activeDocument.path+"/"+app.activeDocument.name;
    new File(theString).remove();
    

     

    If you want to move it to the trash, maybe changePath would work, but you’d probably have to define the proper path for the volume on which the file resides.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 28, 2011 12:02 AM   in reply to c.pfaffenbichler

    You should probably close the doc before deleting it...

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 28, 2011 12:07 AM   in reply to xbytor2

    You’re probably right.

    var theString = app.activeDocument.path+"/"+app.activeDocument.name;
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    new File(theString).remove();
    
     
    |
    Mark as:
  • Currently Being Moderated
    Sep 28, 2011 4:24 AM   in reply to xbytor2

    xbytor2 wrote:

     

    You should probably close the doc before deleting it...

    I think that would depend on why the file of an open document is being deleted. Other than the revert menuItem, an open document is not tied to the file.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 28, 2011 6:20 PM   in reply to Michael L Hale

    The open document has no relation to the file on disk.

    Unless you just opened a document from a file, or saved a document to a file -- you can't even guarantee that the document has a file on disk.

     

    And yes, the examples are very risky because the path may not exist.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 29, 2011 2:28 AM   in reply to cmeira

    ... then you have to reduce the risk

    Well, one could wrap the removal in an if-clause to check for the existence.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 29, 2011 5:31 AM   in reply to Chris Cox

    I have to disagree with Chris Cox. There is a loose relation to the file if one exists. If Photoshop 'knows' there is no file associated with the activeDocument the Revert menuItem is grayed out. If the file is deleted after Photoshop opens the document Revert is not grayed out but using it will throw an error.

     

    The document ActionDescriptor also is effected by whether Photoshop 'thinks' there is a related file. There is a key in that descriptor that only exists when there is a file associated with the file. And you can use that key to guarantee that the document has a file on disk.

     

     

    function hasFile(){
        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;
    }
    

     

    I do understand the point Chris is trying to make. Photoshop does not work on files. It only uses the file to create a document.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points