Preview- move to Trash

When opening multiple .jpg files (or other format) I can use the "Move to Trash" on all but the last one standing?

Here is a example of two images, and if I select one then the Move to Trash works.

single

However if I select all or have only one image showing the Move to Trash is disabled?

multiple

My challenge is that I open a group of screen shots and then review and delete.

Let say I have 50 screen shots and I open 10 of them to work with. The names are

  • Screen Shot 2015-01-19 at 9.14.42 PM
  • Screen Shot 2015-01-19 at 9.14.17 PM

and so on.

Obviously I can not remember the specific name once I close the Preview and now have to find and delete a specific one, since now it is a part of larger group with very "similar" names.

Is there a way to use the Move to Trash on all images including the last one standing.


You can move those files directly to the Trash.

  1. Select them in Preview

  2. Drag them above the Trash in the Dock

  3. Wait for ~2 seconds

  4. Finder window will appear and you can drop those files.

However you won't be able to empty the Trash without closing the Preview window first (the file is still in use).


Preview won't allow you to cmd-delete, or "move to trash", or even drag and drop to trash, the last file it has open. This "feature" was introduced in Lion, and you're not the first person to lament it's inclusion online.

The only useful solution I've found is to create an Apple Script Application that deletes any item dragged on to it and put this application in your dock. Here's how:

  1. Open Script Editor (inside the Applications->Utilities folder) and create a new document
  2. Paste in the following code:

    on open thisfile
        tell application "Finder"
            delete file thisfile
        end tell
    end open
    
  3. Choose File-> Export to export your newly created application, give it a name that's useful like delete.app and save it into your applications folder. Make sure to change file format to "Application"

  4. Drag the application into your dock

Voila! Any file you drag onto this application will now be moved to trash. The last item open will still in fact stay open in preview once you delete it but it will have moved to the trash from it's previous location. It's not an ideal solution, but it's a solution.


If your Preview.app has been made scriptable. (If I remember right Apple may have made it so in later versions, but with no real dictionary)

You can run this Script, Saved in an Run Applescript Action in an Automator Service for Preview.app, no input.

set theDocs to path of (documents of application "Preview")
repeat with i from 1 to number of items in theDocs
    tell application "Finder" to set item i of theDocs to ((item i of theDocs) as POSIX file) as alias

end repeat
tell application "Finder" to delete items of theDocs

I am still looking at improving this as it works well. But it will get ALL open documents. Which each image grouped or not is seen as.

So beware that if you have Preview.app to open in groups or separate windows and more than one window open ALL will be seen and deleted.

Preview.app does not respect the normal understanding of a window. Hence me still working on this


UPDATE:

This (in most cases) should work better. It tries to deal only with the front window and its images.

tell application "Preview"
    set theDocsID to id of window 1
    set theDocsWin to name of (first window whose id is theDocsID)
    try
        set documentCount to word -5 of theDocsWin as number -- the window name has a document count. we can use this repeat for each image.

    on error
        set documentCount to 1
    end try

    repeat documentCount times
        set theDocsPath to path of document of (first window whose id is theDocsID) --the name changes when an image is closed, but the main windows id stays the same.
        log theDocsPath
        tell application "Finder" to set theDoc to (theDocsPath as POSIX file) as alias
        tell application "Finder" to delete theDoc
        close (first window whose id is theDocsID)
    end repeat

end tell

Place this like before in an Automator service.

enter image description here


enter image description here

*


Some background on why this approach: Each image grouped or single image in a Preview.app's window are seen by preview as a window in and of them selves. And the Actual image as a document.

For example you have two images in grouped in one Preview window.

enter image description here

But what Preview.app sees is: Two windows with a document each.

And the frontmost window will always be a the select documents window.

What we see as the main window knows nothing about the windows inside of it.

This means you cannot use documents of window 1 etc. in the normal way. Because if you have a grouped window you will only ever get the selected image in the group.


*