I want to create a macro that will do the following:
Select all files in a given folder
Open all of the files in specific apps according to the extension (all .pdf, .jpg, and .png in Preview, all .doc or .docx in Word, etc.. The trick is the application I want them to open is in one that is not the default application for that filetype—I only want them to open .jpg files in Preview in this one instance, for example, so I don't want to change the default app for all .jpg files).
Wait until the file is open.
Delete the file from the folder.
Is this possible with Keyboard Maestro by itself, or will I need some kind of AppleScript for it?
Specifically I want all the files that were opened to be moved to the Trash. It doesn't matter if the data in them is lost—I only have to look at them for a minute and then close them, so having to go back to the Finder to delete them afterward is just an extra step I'd rather skip.
The first thing you will need is a set of (file extension, application name) pairs. I would personally tend to do that in JavaScript, but you could also use a Keyboard Maestro dictionary:
and then use For Each Item in a Collection both with the The Finder's Selection and the keys in the dictionary, (together with a Split Path action), to match extensions to application names.
To open a filePath with a specific app, I think you may have to use open -a (application name) filepath in an Execute Shell Script action which references KM variable names, but others may be aware of a better route ...
Thank you, that worked perfectly! Just what I needed.
Don't worry about the files being moved to the Trash, either—it's exactly what I wanted. I don't need to edit or save or do anything with the documents. I'm actually just grading papers—I teach at an online school, so I download the submissions, open them to see if they're done correctly, and then delete them. On the very rare occasion that I need to check them again, I can always just re-download them. This macro will save me very valuable seconds and mouse clicks for each document I have to grade—which adds up to a lot over the course of the day.