Opening multiple files in different applications

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?

Delete the file from the folder.

Which file do you want to delete ? One/all of the open files ?

That would leave the data in a very precarious and vulnerable state ...

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 ...

1 Like

I like to use the KM Switch or Case action for this type of use case. It provides a lot of flexibility like:

  1. Using RegEx to match multiple cases (file extensions)
  2. Provide for an "Otherwise" catch all

Caution: The below macro moves each file in the folder to the macOS Trash, which will like impair the app's ability to work with that file.

Here's an example macro, which you MUST CHANGE to fit your specific requirements.

Please let us know if this works for you, and if you have any questions.

MACRO:   Open Each File in Folder with Specific App

~~~ VER: 1.0    2018-11-19 ~~~


Open Each File in Folder with Specific App.kmmacros (5.9 KB)
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.



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. :grin:

1 Like

Oh my. This just gave me an idea. Complex and JMichael are some incredible dudes. Thank you!