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.
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:
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)
and 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.
I get an empty window 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.
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.
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...
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?
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!
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.
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.