Delete a currently-open file directly in the application? OS X's ability to rename or move a currently-open file right inside the application is really handy:



To take it one step further, is there a trick to actually delete the current file  inside the app also? (Obviously 'closing' the file would need to be the second half of the process.)

It would save a lot of time to not have to close the file, manually locate it in Finder, then move it to Trash - but but just delete it right there and then.

I have tried dragging the 'file' (with the file icon to the left of the file name in window title) to the Trash icon on the Dock, but that doesn't actually move it to Trash.

The best I can think of is to add ~/.Trash directory as an item in Finder Favorites, then change the 'Where' in the above screenshot to the created 'Trash' Favorite shortcut, followed by a Cmd+W to close it.

It's a little clunky, but it's not bad.

So is there a nifty Automator workflow / AppleScript (which can then be easily assigned to a hotkey), to make the above process quicker? A single AppleScript that could perform both the step to move current file to 'Trash' directory and then the subsequent Cmd+W keypress after a 200ms gap e.g., would be ideal.
I use this AppleScript:

tell application (path to frontmost application as text)
    set f to POSIX file (path of document 1) as text
    close document 1
end tell
tell application "Finder" to move f to trash


A hackier version that works with a few more applications:

try
    tell document 1 of application (path to frontmost application as text)
        set f to path
        close
    end tell
on error
    tell application "System Events" to tell (process 1 whose frontmost is true)
        value of attribute "AXDocument" of window 1
        set f to do shell script "x=" &amp; quoted form of result &amp; ";x=${x/#file:\\/\\/};x=${x/#localhost/};printf ${x//%/\\\\x}"
        keystroke "w" using command down
    end tell
end try
POSIX file f
tell application "Finder" to move result to trash