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
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
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)
set documentCount to word -5 of theDocsWin as number -- the window name has a document count. we can use this repeat for each image.
set documentCount to 1
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.
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)
Place this like before in an Automator service.
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.
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.