Cannot get variables to work


I've been an avid KM user since v7 but, for some reason, variables have never worked for me, even though I'm copying patterns I've seen others use. Here's a minimal working example that demonstrates this:

The terminal instance ends up with just echo and the variable is empty, even though I assigned it group 1 of the regex match. When I copy the text that triggers the macro, the regex action shows that App UUID contains the UUID. What am I doing wrong? Any tips would be much appreciated.


What do you see if you add a Display Text: Window action just before the iTerm paste with this as the display item:

%Variable%App UUID%

Is there content there?

Also, pretty sure you want just normal text, not styled text, for the terminal. But that shouldn't affect not getting anything.


1 Like

Thanks for the quick reply! I tried with normal text, typed text, and styled text, and none worked. Adding a Display Text before the paste results in an empty window:

This is the action:

This has been my experience with variables in KM since day one, so I'm clearly missing something.

The problem isn't with your variable, it's with your regular expression: The empty box means there's nothing in the variable.

Can you post the clipboard data you're trying to format, and the format you're trying to get it into? (That is, a before and after of the UUID data.)


1 Like

The regex is working. I managed to take a screenshot of the action (sorry it's cut off, but I had to hit the screenshot shortcut quickly), showing that group 1 (which is supposed to capture a UUID), is assigned to App UUID.

The string is (e.g.,):
App UUID: 87175313-2235-4efe-8ee3-ef422f0ea634
and for the regex I've tried
App UUID: (\b[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}\b)
App UUID: (.+?)$.

They both "work" in the sense that group 1 gets assigned to App UUID when I copy the string to the clipboard, but either the variable gets overwritten somehow or %Variable%App UUID% is wrong.


Can you test the attached macro? Does it work when you have the App UUID on the clipboard?

appuuid.kmmacros (3.8 KB)


1 Like

I get an empty window :sob: That action is identical to mine (modulo the iTerm stuff).

Could it be because my user account doesn't have admin privileges (i.e., it's a "Standard" account)? Does KM require elevated privileges for this kind of thing? I don't see why it would, but I can't think of any other explanation.

Yea, that's why I wanted you to test it, just to be sure there weren't any weird invisible characters (somehow) causing issues.

Maybe, but before we go there, choose Help > Open Logs Folder, open the engine log, and see if there are any interesting messages there.


1 Like

How about these?

2023-12-15 18:52:25 FMDB Error: Unknown error finalizing or resetting statement calling sqlite3_finalize
2023-12-15 18:52:25 FMDB Error: executeUpdate sqlite3_finalize returned (11: database disk image is malformed)
2023-12-15 18:52:25 FMDB Query: commit transaction
2023-12-15 18:52:25 FMDB Path: /Users/fort/Library/Application Support/Keyboard Maestro/Keyboard Maestro Variables.sqlite
2023-12-15 18:52:25 Assertion Failed: ([gDatabase commit]), file: …/Source/Defines/, value: 0

If database corruption is the cause, then it's somehow happened to me on three different machines since v7, because I've never been able to get variables to work.

Yea, that looks pretty bad :(. Were all the machines non-admin users?


1 Like

Am I allowed to jump in this late and speculate? I speculate that you have something else (possibly a macro) erasing the clipboard. Try this instead...


1 Like

Yes. They're my machines but I prefer to set them up that way for security, and then use sudo when I need to run something as admin.

Thanks for that, but I still get an empty window with this:

Something is very fishy. Could you turn on the debugger and press the X button so you can see the variables in the debugger window and step through your macro to see if the variable holds the right value at all times?

1 Like

Step 1:

Step 2:

Throughout, the Search Text action shows that App UUID is 87175313-2235-4efe-8ee3-ef422f0ea634`:

I see. I'm trying really hard to help. It's a stumper.

1 Like

Thanks @Airy and @griffman ! I think it's likely to be a permissions issue and, to be honest, I've found other scripting solutions when I've had to use variables, so it's not critical for me to solve this. It would be a "nice-to-have" but probably not worth spending any more time on it. Thanks again for your help though!

I'm not giving up. If it's a permission issue, we can look at those. I'm not sure about that yet though.

1 Like


Much appreciated. I'm going to be offline for the next few hours, and then asleep (I'm in Europe), but I'll be back tomorrow.

Is this what is selected on your Display action's cogwheel? One of my theories is that you saved your Display action as a favorite with the wrong setting here and you keep creating it from your favorites.

Screenshot 2023-12-15 at 13.29.59

Nah, I reject that theory. Because I see from your screenshots (assuming that you did a "Try 2 actions" menu item,) that the variable wasn't set after your first action, even though the Editor says it would set.

Now I'm leaning in the direction of permissions. But tell us what version of KM you are using and what version of macOS you are using.

There may be one idea worth trying yet. Instead of inspecting the variable with the debugger, try inspecting it with either the Editor's Value Inspector or the Editor's Preference / Variable window. When it comes to empty variables, the Editor's list and the Debugger's list can differ. There might be a clue there.

Just for the record, your macro works fine on my Mac.

1 Like