Setting variables from clipboard seems broken

I made this very simple test macro. I want to see what's in the clipboard and save it to a variable (to then do some stuff with it, but that doesn't really matter).

But somehow the variable always ends up being NULL and not the actual value stored in the clipboard. This is doubly confusing as the macro is actually showing the correct value from inside my clipboard. I just copied a text saying "this is a text I copied" and it's displayed correctly.

Any help here? I feel like I'm going insane as this seems so simple. Is there some known bug here or something interfering with the clipboard?

On a sidenote: I would ideally want to just use the copy action before so I don't have to CMD+C myself before but that just makes the whole thing bug out too.

(I am running Keyboard Maestro 11.0.2 on Mac OS X Version 14.2.1 (Build 23C71))

Thank you!

Hi, and welcome to the forum!

My first basic question would be: Are you certain you are actually running your macro?

The variable "test" wont be set (altered from NULL to this is a text I copied) until the macro has ran at least once past your first action there.

My next question would be if you might have another macro, triggered by a Clipboard Changed Trigger, setting the same global "test" variable to NULL

EDIT: Or I see now that my second question does not make sense in the context of your actual macro

Yes, I'm certain. That's why I added the function afterwards to Display Text, which displays the variable I just set. So this happens and I get a big NULL on my screen.

I don't have any other macros running on Clipboard Changed trigger.

Would it be possible for you to upload your actuall macro? Then I could see how it performes here on my system

Copy Text and display.kmmacros (1.8 KB)

here you go. thank you so much for your help!

It seems to work perfectly here, so this is all strange. Sadly, I am pretty much at my withs end here then, and hope that anyone else can chime in with any form of insight

Where could that "NULL" come from though?

Do you find anything in your KM if you search for "NULL", with the All Macros smart folder selected (the purple one at the very left of your editing window)?

Yeah it feels super weird. I'm wracking my brain trying to figure out if I have some software running that messes with the clipboard or something like that. But it feels especially weird as the preview is correct..

Thank you for trying though.

Definitely weird
But does the Display text pop up display correctly on your system if you add a Pause between the two actions also? Like a 5 second pause, or something like that

I tried that because I saw some answers referring to needing to wait a bit for the clipboard, but no luck :confused:

Change your Set Variable action to set the text to something like:

The clipboard is “%SystemClipboard%”

Then you can see whether it is the token failing to return the clipboard, or the action failing to set the variable.

In the former case, it could be that the Keyboard Maestro Engine is unable to read the clipboard for some reason. There isn't really any good reason for that, so I'd be restarting at that point just to ensure there is not something screwed up in your system causing a problem.

In the latter case, it could be that the variable database has become corrupted and needs to be trashed.

Also, you should always use the long form of variable reference, %Variable%test% rather than the short form %test%, as the later can easily be confused with tokens and so it not recommended in general.

1 Like

So, I just tried this and something weird happened. When I ran it the first time it actually just worked. And then when I ran it again, the variable stored in the first run stayed the same and wasn't set to the new clipboard. The preview however is still showing the correct data.

Very strange. How could I trash the variable database and restart it? I don't have anything precious in there.

Nevermind, I found a post of yours describing how. I tried and the same happened again. The first time it suddenly worked, every time after the variable didn't change.

first try (after running)

second try (after running)

It's so strange because Maestro can evidently read my clipboard, but somehow putting the clipboard into a variable doesn't work. Using variables works normally in other macros. I also deactivated all other macros now, to make sure nothing is interfering but still the same.

Anything else I can try? I found a way around it in my initial use case but would still like to optimise it if possible.