Set Multiple Variables Plug In Action

Set Multiple Variables Plug In Action

Purpose

The TFL Set Multi Variables Plug In action for Keyboard Maestro provides the ability to assign values to many KM variables with a single action, instead of having to use a separate KM Set Variable action for each assignment.

Benefits

  1. Using a single action instead of many to set the values of variables keeps the overall size of the macro small and is quicker to create.
  2. It is easy and quick to disable/enable multiple variable assignments with a single click, for debugging purposes.
  3. The plug in reports all errors in the KM log in a way that makes identifying errors very easy.

Download

Download the plug in file to your Mac:
TFL Set Multi Variables.zip (552.8 KB)

Installation

  1. Drag the downloaded zip file from Finder and drop it onto the Keyboard Maestro icon in the dock.
  2. Stop the KM Engine using File>Quit Engine.
  3. Restart the KM Engine using File>Launch Engine.
  4. The TFL Set Multi Variables plug in action can now be added into your macros as normal from the Third Party Plug Ins section of the KM Actions library.

Usage

After adding the action to a macro you will see this:

Set Multiple Variables Plug In Action

The Variables__Values field is where you list the KM variables with the values that you want to assign. These Variable/Value pairs must be separated by the delimiter specified. By default, the delimiter is the comma (,).

Each Variable/Value pair must occupy just a single line of text even after any tokens have been expanded - any more and the plug in will generate an error.

Examples

Example 1

Set Multiple Variables Example 1.kmmacros (2.9 KB)

Set Multiple Variables Example 1

This example shows a possibly typical use of the plug in.

Notes

  1. You can use tokenised variables to specify the values to be assigned. In this example the value of %Variable%LocalVariable% is assigned to Local_Var1.
  2. The delimiter is very flexible. Here it is set to == which possibly makes reading the assignments much easier.

Example 2

Set Multiple Variables Example 2.kmmacros (3.1 KB)

Set Multiple Variables Example 2

This macro shows the use of a KM variable to hold the assignments.

Interpreting Errors

While using this plug in you will probably encounter occasions when it throws an error and stops the execution of your macro. The quickest way to find out what has gone wrong (if it isn't obvious) is the look at the KM Log.

In the KM Editor use the menu Help>Open Logs Folder and then open the Engine.log file. Easier still, just use this macro

The log file will contain 2 entries describing the error, as shown here:

The first entry (labelled "A") comes from the plug in while the second entry ("B") comes the KM engine. In both cases the information can be interpreted as follows:

  1. The timestamp for the error.
  2. What the error occurred in (the plug in)
  3. The error message.

It is the third one, the error message, that tells you what went wrong.

In this example

"Bad assignment for Instance_Var2=This is instance variable 2"

tells us that we mistakenly used an incorrect delimiter: it should have been a double equals sign "==" rather than a single one.

Disclaimer

You use the plugin at your own risk and the author accepts no liability for any loss; Testing of the plug has been performed but YMMV. You have been warned.

3 Likes