Open File in Finder - Filtering File Type

Open file in finder - filtering file type

This prompts the user to open a folder we want to work with. Eventually I want to open each file in that folder, but only if it's a specific file type. It also needs to skip files other than our desired file type and if there's subfolders in that folder.

How can I work in a filter like this?

Use a sequence like:

Note that you should generally never open a folder with the Default Application, always open it with the Finder - it is possible for the system to decide some random application “owns” folders. Same for “.app”s, always open them with the Finder (or use the Activate a Specific Application action).

Thanks Peter for the response and helping me with outlining a solution.
I've written this attached Macro that successfully filters out files like *.txt, and it also "bypasses" subfolders (which is great in my case).
zzz Open Specific types of Files in Finder, only.kmmacros (6.7 KB)

However, I'm finding it hard to validate aliases. It seems like aliases don't have definite extensions, or I might be missing how to implement this?

You can use this:



tell application "Finder"
  set theSel to the selection
  set theItem to item 1 of theSel
  set classItem to (class of theItem) as text
end tell

return classItem

Hey Folks,

Keyboard Maestro can determine if a file is an alias:




I'm having a problem with that KM Action.
When I select an alias file using the select button on the Action, and pick an alias file, it returns the target file, not the alias file.



@peternlewis: Is this a bug or by design?

Hey JM,

That's clearly a bug – but I'm not sure its Peter's bug. We'll see what he says.

In the meantime try drag and drop.

The Finder Selection Collection works correctly on the alias file as well.


It's not really a bug, it is by design - when you select an alias, it is generally resolved. You have to actually work quite hard to not resolve the alias when using it.

Thanks Michael. This does the trick :slight_smile:

I have updated the KM Wiki to make this clear:
Get File Attribute Action

Since we now now that this returns the original file, I would like to just check that the original file that's linked from the alias, is also of a certain extension type.
Can i use this Get Content to save as a variable?

This has already been done. The to variable field has the KM variable to be set, in this case it will be "fileType":


3 posts were split to a new topic: How Do I Determine that a File alias actually points to a valid path?