Open File in Finder - Filtering File Type


#1

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?


#3

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


How Do I Prompt for Folder, and Limit File Selection to aliases?
#4

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?


#5

You can use this:

image

AppleScript

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

#6

Hey Folks,

Keyboard Maestro can determine if a file is an alias:

image

-Chris


#7

Chris,

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.

image

image

@peternlewis: Is this a bug or by design?


SCRIPT: How To Determine If Finder Item is Alias or SymLink
#8

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.

-Chris


#9

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.


#10

Thanks Michael. This does the trick :slight_smile:


#11

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


#12

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?


#13

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

image