"Open a File, Folder, Application" not accepting variable?

This is not exactly what you are asking for, but I think it might help:
###MACRO: [KM] Display Macro Error

Please feel free to post any feedback on the macro topic.

OMG this is gold! It forced me to poke around and find the recently-run and recently-used buttons. They were not obvious, and I recommend putting them next to each other. Perhaps both buttons would have a clock, one with an inset key and the other with an inset pencil?

Also not obvious was press-and-holding those gives a pop-up of the most-recent run/edited (it wasn’t clear what clicking once did)–so ideally have a drop-down arrow (like with font size button) as part of the button.

Great to know about option key as well :slight_smile:

Maybe an option could be that any time a KM notification is clicked that at least the running macro is shown in the editor?

Thanks JMichael, will check it out! I assume you’re also from Australia given the hat? :wink: [or TX!]

@ajg23, you’re welcome.

Well, the β€œTX” is a BIG clue. :wink:
I guess you didn’t recognize the avatar as being from Indiana Jones. :wink:

I do like the outback hats though.

yeah I thought it was Harrison Ford, but just continuing to play with the Australian topic :wink:

I once had this problem because my variable was a date that was formatted with slashes. So rule that out…

Hey Folks,

One last thing.

When troubleshooting paths always output the complete path to a variable.

Then output that variable to a text editor like BBEdit, so you can visualize it completely.

If it’s an existing path you can test it in the Terminal like this:


file ~/test_directory/test.txt


/Users/myUserName/test_directory/test.txt: ASCII text

You can do the same thing without leaving BBEdit by:

Using a worksheet if you have the commercial version.

OR by writing it as a shell script (in either the commercial or β€œlite” versions).

#!/usr/bin/env bash

file ~/test_directory/test.txt

Run using the β€œRun” menu item in the shebang menu (#!). I have this bound to Cmd-R for convenience.

Bitter experience has taught me to NEVER write a macro like:

(Open or some other command) <some complicated string with text-tokens and/or variables>

This makes troubleshooting a nightmare.

If possible I always construct path-strings in such way that I can easily eyeball them.


1 Like

I completely agree with Chris.

To All:

Here’s an AppleScript handler you can use to validate whether or not a file/folder exists:

on doesItemExist(pPosixPath) -- @Path @File @Finder @ASObjC
  (*  VER: 1.0    2017-03-02
  PURPOSE:  Determine if the Path Actually Exists
    β€’ pPOSIXPath    | text  | POSIX Path to check
  RETURNS:  boolean β”‚  true IF the file/folder does exist; else false
  AUTHOR:  JMichaelTX
  BASED ON:  Script by Chris Stone & Shane Stanley
    1. Does a NSURL Have a Valid Target
  ##  Requires:  use framework "Foundation"
  local myNSURL, doesItExistBool
  --- Expand tilde (~) in Path (if it exists) ---
  set pPosixPath to (current application's NSString's stringWithString:pPosixPath)'s stringByExpandingTildeInPath
  set myNSURL to current application's |NSURL|'s fileURLWithPath:pPosixPath
  set doesItExistBool to (myNSURL's checkResourceIsReachableAndReturnError:(missing value)) as boolean
  return doesItExistBool
end doesItemExist
--~~~~~~~~~~~~~~~ END OF handler doesItemExist ~~~~~~~~~~~~~~~~~~~~~~~~~

You could easily put this in a Execute_an_AppleScript action (KM Wiki), and pass the path from a KM Variable:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

tell application "Keyboard Maestro Engine" to set posixPathStr to getvariable "File_Path"

return doesItemExist(posixPathStr)

--- Put the doesItemExist() Handler below ---


I'm using the US International PC keyboard on my MacBook Pro to insert the tilde. The key to insert it is positioned at the right of the left SHIFT key. When I press it, the dead key mechanism is activated:


Then I press space to have the tilde actually inserted: ~.

It took me ages to notice that in Keyboard Maestro the thus inserted tilde isn't the correct one: it's positioned higher. So I copied the correct one from your macro. Is there an easier way to insert the correct tilde, even with the US International PC keyboard activated?

This is probably farfetched, but should Keyboard Maestro have warned my for using the wrong tilde?

Anyway, thanks for your example macro that finally solved this mystery for me.

You could use a KM-only macro that waits for a certain string to be typed and then replaces with the β€˜right’ tilde.

I don’t suppose the β€˜wrong’ tilde would work in that case because of the dead-key thing, perhaps you could automatically substitute two hyphens -- instead?

So typing:

would result in:

1 Like

My reading (and testing) indicates that these sequences work on the US International PC keyboard:

  • ~ followed by an accentable character (eg a) give that accented character (Γ£).
  • ~ followed by a space gives the tilde character (~).
  • ~ followed by any other character (eg / in your example) gives the accent by itself followed by the character (˜/).

So my guess is that you simply didn’t press the space after the tilde in this case and got the accent.

No, the accent character (˜) is perfectly legal in file names. Note that in places where Keyboard Maestro excepts a full path (eg reading or writing a file), that path would not be acceptable since it is not an absolute path, however if you renamed or moved a file to that path, then the path would look like a relative path and so it might work as a file name, depending on the circumstances.

1 Like