I have completely redesigned this macro from the ground up. It's not even really the same macro but since I already had a well-established topic on it I will just update it here. The original post and macro information can be found at the very bottom of this post.
This macro is designed to replace an action(s)' global variables with local variables and vice versa. Click on each section below to read more about it, to see the screen recording and also a screenshot of the macro.
Screen recording (click to expand/collapse)
RELEASE NOTES, INSTRUCTIONS AND DISCLAIMER
Purpose of this macro (click to expand/collapse)
Convert global variables to local and vice versa.
How this macro works (click to expand/collapse)
First, select whichever action(s) that contain variables you would like to convert, then trigger the macro.
By default, this can be done by the menu bar group icon or by hotkeys.
The action(s) you have selected are the copied to the system clipboard as XML.
Then, supposing you are converting from local to global, the clipboard is searched for your local variable prefix and replaces it with your global variable prefix (or vice versa)
By default, the prefixes are local__ for local variables and debug__ for global variables since that is the naming convention I use while building/editing/debugging.
If you use a different naming convention, you will need to change those portions of this macro to match whatever you use.
Once the prefixes have been converted, the updated XML is pasted into KM which automatically pastes it as the same actions but with the updated variable prefixes.
If you selected to delete the old actions, then they are deleted before pasting; otherwise the new actions are pasted below the originals.
How to configure this macro (click to expand/collapse)
Indicate in the purple-colored variable whether you would like the selected action(s) deleted by default by putting Yes or No (Yes is currently selected which will result in them being deleted).
If you run the macro via the prompt, you can also unselect the checkbox if you do not wish to delete the original action(s).
The default triggers are ⌃⇧⌘V and the group status menu.
If you trigger the hotkey without hold it down, they will be converted to local variables.
If you trigger the hotkey and hold it down for at least 0.2 seconds, they will be converted to global variables.
Obviously this can be modified to suit the end-user's needs.
How to use this macro (click to expand/collapse)
Select the action(s) that contain the variables you wish to convert, and trigger the macro.
If you trigger it using hotkeys, it will run instantly.
If you trigger it via any other method, it will show a prompt asking you what you would like to do.
Disclaimer (click to expand/collapse)
TL;DR: I built it and it works for me. You can share/modify it how you want. But don't blame me if it doesn’t work for you
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
CURRENT VERSION: 2.0.1 (Wednesday, February 16, 2022)
v2.0.1 Wednesday, February 16, 2022
Added notification if action(s) contain a display text in a window action since it's XML is encoded and cannot be converted.
Original Post Information and Macro (from November, 2021 - click to expand/collapse)
If you're like me, when you're building a macro you may like to use global variables to be able to see their value in real time to make sure everything works properly. However, you may want to convert those to local variables when you're done building the macro, or vice versa if you have to edit an already built macro.
This macro is not magic in that it will not automatically convert all those variables with no user input, but it will somewhat reduce the time it takes for you to convert them. For me, the longest part of this process was simply deleting the prefix I would use for my debug variables and typing
local_, and I got tired of mistyping and not realizing it until the macro stopped working, and then having to track down that one variable that was called
locl_iHateTypos instead of
All you have to do is click in the field where your variable is, and trigger this macro. It copies the text to the clipboard, and then uses a simple search and replace feature to replace
debug_ and vice versa. The same macro accomplishes both purposes depending on if you continue to hold the modifier keys after triggering it or not (or your user prompt selection if ran from the Group's Menu Bar). More information on this in the macro comments.
I have used this already in a variety of macros and it seems to work fine for me. However, use with caution the first few times you use it because...well, you just never know haha. Let me know if you have any issues, questions or suggestions!
Previous versions (click to expand/collapse)
v2.0.0: Tuesday, February 15, 2022
NOTE: This will not convert variables that are encoded as formatted text (such as in a display text in a window action)
v1.0.0: November, 2021