Copy straight to variables

Stupid question: Is there an action that allows you to copy something directly into a variable?

As far as I've learned the only way is to first use a Copy action an then move it into a variable. Unless I'm missing something.

Thanks, Xavier



NB ALL variables are held internally as strings.

Thank you for your reply but either you misunderstood my question or I'm misunderstanding your answer.

I'm aware that we can set a Variable to any string at will. What I meant was if there's an action that can copy something via CMD+C and put that straight into a variable (without using a "Set Variable to Clipboard" action). Essentially saving a step.

Hope that makes sense.

If I have understood your reply, then not to my knowledge.

If you want to elaborate on what you actually trying to do......and why you want to save a step in the macro execution

Oh, this is just a question that comes up to my mind every time I create a macro. The more experience I have with KM the fancier and longer my macros get the more I try to streamline things.

You see, when macros start getting long, every step I can save counts.

That's all : )

I hope the developer would consider adding such an action one day.

"Keyboard Maestro is the best software investment I ever made"

He should make t-shirts that say that and sell them!

Short answer: No.
Even a copy to Named Clipboard goes through the System Clipboard.

Although I generally prefer to then set a KM Variable to the CB, there are many KM Actions that work directly on the CB.
If you don't want your Clipboard or KM Clipboard History cluttered with these copies, then you can just add a Delete Past Clipboard action, with a 0 for the Past CB.

Have you checked out the excellent macro system MACRO: [KMFAM] Favorite Actions and Macros by @DanThomas?

It is basically like a template system for KM. So you could store the 3 Actions to copy, set var to CB, delete past DB, and instantly paste them into any macro very easily.
You could even put them in a Group Action so that you could close the Group to eliminate clutter.

Finally, I'd suggest as a best practice that you try to avoid really long macros, scripts, etc. Try to modularize functional elements for reusability. For KM Macros, you would create what I call "Sub-Macros", which are just normal macros called by an Execute a Macro action.

BTW, but KM Instance Variables are designed to work well with sub-macros while avoiding data conflicts with other macros.

Good luck!

1 Like