File Name and Path of Currently Selected File in Pathfinder: Something Basic That I Don't Understand


I am working on a macro using file name and path and wrote the one action macro below to make sure that I understand the filename and path variables.

I realize that there is something major that I don't understand.

If I first select a file in Pathfinder and than run the macro below, nothing is displayed
thanks in advance for your time and help

A Keyboard Maestro Variable is something that you define. You decide what the Variable is called and what text is stored in it. There is no text stored in it until you put some in - that's why your one Action Macro, Display Text is showing nothing.

The fact that you have given your Variables names that include the words "path" or "file" means nothing to Keyboard Maestro.

Keyboard Maestro does have inbuilt Tokens which look similar to Variables but are different in that they do get values automatically.

%FinderSelection% is an inbuilt Token. It will get the path and name of a selected file in the Finder. Notice it doesn't have %Variable% in front of it.

If you wrote %Variable%FinderSelection% that would be telling Keyboard Maestro to use a Variable that just happens to be called the same as a Token. And that Variable would be empty until you put something in it.

Keyboard Maestro has Tokens for lots of things (but not everything). You can check out the complete list of inbuilt Tokens here:

In addition to everything I have said above, Keyboard Maestro doesn't have any inbuilt Tokens to work with the app Pathfinder. You would need a more complex Macro to get this to work. Try a search for "Pathfinder" on the Forum.

Keyboard Maestro does have inbuilt Tokens to work with Finder. So, if you selected a file in Finder and ran the below, you would see how a Token could be used in a simple Macro.

EXAMPLE Display Finder Selection.kmmacros (2.3 KB)


a great explanation. I will review the list of tokens. I took for grated that if a variable name was "offered" by KM in the list of variables, it was a token.
thanks very much !

1 Like

Ah yes. That list is a list of all the Variable names that have been used in your Macros.

Just above that menu item is a similar one that lists all the Tokens.

Or if you are in a field that will accept Tokens, if you press βŒƒβŒ˜T you can search for a Token to insert by name.


great !! thank you !

Hey @ronald,

Please post actual testable macros and not just images.

Finicky little details hide in macros that are not deducible via images and/or prose, and those are often key to solving a given problem.

The pictures you've shown are virtually meaningless, because the entire macro is not described – nor is there a downloadable, fully visualizable, testable macro file.

Even if you had created a proper image of the entire macro there would still be some of those finicky details hiding behind closed doors...

Note that Keyboard Maestro will accept variable names in the legacy variable format:


Personally I wish @peternlewis would sunset that feature, because it periodically causes head bashing against the wall problems for users who either don't understand the difference between variables and text-tokens or inadvertently use a token name as a variable name and get very unexpected results.

If Peter jumps in I imagine he'll say: "Changing that would break some people's macros, so ixnay...", although this is one of those things (imo) where the minimal pain for a few users would be worth it.

In any case – I vehemently harp on this point:

<soapbox on>

NEVER, EVER use token notation as text-variable-notation.

I.e. never, ever use %VariableName% when you mean %Variable%VariableName%.

If you ever do this it almost certainly will come back to bite you at some point, and you might well waste hours or days trying to troubleshoot an easily avoidable problem.

Also – if you use the legacy notation you cannot ever be certain at a glance whether a string bracketed with percent signs is a token or a variable – while If you take my advice then you will always know at a glance whether you're dealing with a token or a variable.

I learned this from hard experience...

</soapbox off>

Take Care,

(Keyboard Maestro Moderator)


Thank you VERY much for taking the time to explain this to me. It is greatly appreciated, and nothing to do with a soapbox.

Take care.


+1 :+1:

1 Like

Path Finder has a very rudimentary AppleScript dictionary, and you can get the path of the selected item.

Cocoatech is really bad at AppleScript though (and doesn't care), so it takes a little finessing to extract useable output.

I have posted a number of times on the forum about working with Path Finder using AppleScript:

You can also copy the path and bring it into Keyboard Maestro using the System Clipboard.


1 Like

Yep. It's a feature I mostly wish I had not created, but it is unlikely to change. Plus for cases like %Local Whatever% it actually works in a safe manner as a short form.