Feature Request: Set Values for "Multiple" Variables in "One" Action

Well... that makes perfect sense. Thanks for your help, I was able to get it working properly. This is a nice way of handling things because on some of my more complex macros I have 10, 20 or even more variables that I set explicitly, and this makes the macro a little more concise to read. Now I can use the same method to delete them all at the end of the macro.

1 Like

I don't know if anyone else has put together an AppleScript version, but here's my attempt:

Set Multiple Variables from Variable-Value Pairs (AppleScript).kmactions (3.0 KB)

3 Likes

Was searching for something else when I stumbled upon this thread again, and realised that what was proposed by @peternlewis in post #36 can be done allot simpler — also using a For Each, set up like this:

Set Multiple Variables To Separate Values — Using For Each.kmmacros (16 KB)
(v11.0.2)

This approach might only work with KM11, as this was the version where it became possible to use variable array syntax directly within the Set Variable to Text variable field. But as it is not here directly setting a variable array element, only pointing towards the variable name from another variables array, it might also work for versions prior to KM11 as well.


As text fields, or text lines, themselves wont get affected by the %Delete% token, this approach also works for deleting all listet variables, like this:

Keyboard Maestro Export

All though setting multiple variables, all to the same value, can be done even simpler, like this:

Delete All Listed Variables — Using For Each.kmmacros (18 KB)
(v11.0.2)


EDIT: And heres a similar approach to deleting multiple global variables, only here done through a subroutine:

Delete Multiple Global Variables CALLER.kmmacros (17 KB)
Set Multiple Variables- All to Same Value SUBROUTINE.kmmacros (16 KB)
(v11.0.2)

Macro Images

Using this same subroutine for setting variables of course only works for global and instance variables.

4 Likes