How can I set up a shortcut on macOS Monterey to delete selected files?
Solution 1:
You can reference the input files directly by using "Get Variable" and then attaching the Delete function.
However, as a precaution macOS will still ask you another time if you want to allow the shortcut to delete the file, so you might want to handle the file deletion directly in the AppleScript using something like
if answer = "Yes" then
tell application "Finder"
delete file input
end tell
end if
Keep in mind that this will only work if the input is a single file, not a folder or multiple selected files so you'd have to take additional steps to handle those cases. Also, the files are not immediately deleted but instead moved to the trash. Personally I'd suggest thinking about going for a Shell Script solution instead.
Solution 2:
With the help of @KevinGrabher and a bit more Googling, I managed to come up with the following partial solution:
This mostly works, but the keyboard shortcut that I've tried to set up in the right sidebar doesn't. I'll post a separate question about that and link to it from here when I'm done.
EDIT: It seems as though all that was needed to get the shortcut to work was a system restart! All good now :-)