Hi @ronald - the direct answer to your question is you can use %user_input% and %Variable%user_input% interchangeably. In other words, they both produce the exact same result: the value of the variable in question. (IMPORTANT: you must capitalise the "V" in "Variable".)
The alternative answer is this: you should never use %user_input% to get the value of your variable. You should always use the form %Variable%user_input% instead.
Why is that?
Well, as you know KM provides many in-built text Tokens such as %SafariURL% and %TriggerValue% and %UserName% - see the whole list of them in the KM wiki
Because of this, it would be easy to confuse your use of the variable token %user_input% with a KM text token - simply because of the way they look similar. Several KM experts in this forum have said that it is always best to keep potential confusion at a minimum and make sure that when you want to get the value of one of your variables you use the full form which is %Variable%user_input%
It is up to you which form you use, though. Personally, I always use the longer form, %Variable%user_input% even though it means more typing!
Thank you very much @tiffle for your crystal clear and educational reply. I will always use the longer form.
Thank you @cdthomer for your suggestion. I tried Typinator and it works, but would prefer to use to use a KM macro (with its keyboard shortcut) instead.
The objective is to convert selected text (namely the variable itself) to the longer format.
I was wondering if either of you would know how I can fix this macro.
If I type user_input → select text → run the macro, I get a blank, clearly because there is something wrong with the format of %Variable%%SystemClipboard%%, most likely because there are so many % that the KM engine gets confused.
Hi @cdthomer. Based on information from you and others on this forum, I decided it was time to check out Typinator. Also, it turns out I had an ancient license (from a software bundle purchased years ago), so I was able to purchase an upgrade at a discount.
I've not given it much time, but I must say that the interface is unique. What's the best way to get started?
In the text %%Variable%%%SystemClipboard%%%
KM interprets %% literally as a single percent sign % and does not treat it as the beginning of a text token.
EDIT: I used the KM Copy action instead of the Cut action - you can stick with Cut or use Copy - both work.
Hey Jim, that's great! For a little more background on my Typinator experience, I downloaded it, used it very little for a number of months and then phased it out as I built my Keyboard Maestro library. But then as my Keyboard Maestro library started to become too large I realized I needed to transition back to a dedicated text expander app for a lot of my simpler macros.
As for how to get started with it, besides downloading my awesome macros?! Haha, just kidding, forgive my shameless self-promotion.
One thing I really appreciate about Typinator is the great user guide which outlines a wide variety of things you can do with it. Some of my most commonly used expansions are used to input my email address, phone number, favorite emojis etc.
Lately I have been converting a lot of my work-related expansions into RegEx expansions which allows me to expand them using a variety of abbreviations, much like Keyboard Maestro does with it's typed string trigger. This is extremely helpful for complex medical terms that I might misspell when taking notes.
That should get you started and of course I can share more things I do with it if you'd like.
The variables that are prepended with double underscores omit anything behind those underscores when they are displayed in a prompt. So even though the variable is still Local__Name of Variable, the only portion that is visible in the prompt is Name of Variable which makes the prompts look nicer.
I wrote to the developer of Typinator (Gue, very nice). The longer version of the variable (using %variable% as a prefix) can be created by text expansion, simply by putting the copying the variable to the clipboard and using the following as an expansion:
All of this inspired me. In Typinator \b(\w+)//v → %Variable%varName% where "varName" is the last typed word. No need to copy or even select. You could even have it add the "local__" if you want.
Bummer is: I know so much more now than when I started with Keyboard Maestro (heh, just typed 'kbm') that I need to go back and refactor every macro.
Hi @Zabobon, thanks for sharing your naming conventions.
I use a lowercase local with two underscores for variables that are used in Prompt For User Input dialogs since, when rendering a dialog, the Keyboard Maestro engine automatically excludes any prefix that includes two underscores.
But for all other local variables I use one underscore. That helps me easily identify the two groups. I find that the underscores also serve to make the variables easier to read.
For global variables and dictionaries, I also have conventions:
Naming Global Variables and Dictionaries
For persistent data, I've generally moved away from storing persistent information in global variables in favor of dictionaries. However, when I do use a global variable, I name them as follows:
jsXXX_YYYY where: 1) js are my initials; 2) XXX is a short acronym or abbreviation for the macro; 3) YYYY is a description for the variable. For example, suppose this macro was mine, I would name the global variable: jsSEP_SearchWebsites
For global variables used in Prompt For User Input dialogs, since, when rendering a dialog, the Keyboard Maestro engine automatically excludes any prefix that includes two underscores.
This convention provides the following:
It's highly unlikely that my global variables will collide with variables from another macro.
In the Keyboard Maestro Preferences > Variables all of my global variables are grouped, first by me (js), then by macro. This grouping makes it very easy for me to clean up the global variables if I decide to retire a macro (or upgrade one by moving from global variables to a single dictionary).
Since dictionaries are also global (even if they are harder to see—since they are not in the Preferences), I use a similar naming convention. For example for this macro, I'd use: jsSEP_dict and have a key named SearchWebsites.