Syncing Variables via Dropbox

Hello all, first time poster and bona fide noob here.
I've been having a lot of fun with KM the past couple of weeks but I've run into several roadblocks.
I've taken the Macsparky course 2 times so far and watched just about every youtube video I can find.
I'm keen to learn more, as I'm loving what it can do.
I use KM at home and at work, and I sync via dropbox. I'd like to sync the variables as well. I do see there are a couple of posts on this, but from what I can read, adding on to old posts is frowned upon, so, I'm starting a fresh post.
I've created a folder in "Dropbox called Keyboard Maestro Variables Sync Folder". I've saved each variable as it's own .txt file with "SYNC_[variable name]"
I'm lost as to where to go from here. Can anyone point me in the right direction?

You use the Actions Read a File and Write to a File to do this (setting the Read a File Action to read to a Variable).

An example of a use of this is a Counter where the Counter goes up by 1 each time a Macro is run. You might want to always have the latest count no matter what Mac you are working on.

Click to Show Image

But a lot of the time Variables are set by the Macros themselves and as these Macros will be the same on all your Macs (via Syncing) they should work the same way on all your Macs.

Here is an example of what I mean:

Click to Show Image

That magenta Action will be the same on all your Macs. If you edit the Macro and change the text, it will change on all your Macs.

The majority of my Macros use Local Variables which only last for a single Macro run.

Even if I do need a Variable to persist between Macro runs (a Global Variable) it usually works fine to have them stored separately on each Mac. An example of that is using a Variable to store a setting from a choice of settings to make it a kind of default setting for the next run of the Macro.

  1. Macro prompts me to say whether I want choice A,B or C

  2. Choice is stored to a Global Variable

  3. Next time Macro runs it selects that choice as the default (because it has been stored to a Global Variable).

  4. The first time I run that Macro on another Mac, I will have to make the choice again. But after that one run it is remembered.

Apologies if this is too much information. But the point is that a lot of the time you won't need your Variable values to sync between your Macs.

For the times that you do, the Actions Read a File and Write to a File will do it.

3 Likes

If you really want to do this notwithstanding @Zabobon's very wise advice I have a couple of macros that let you save and retrieve the KM variables of your choosing in a folder also of your choosing.

Here is the macro to save your KM variables:

KM Variables - Save.kmmacros (5.3 KB)

Click to see macro

and here is the macro to retrieve your KM variables:

KM Variables - Retrieve.kmmacros (10 KB)

Click to see macro

Things you should take note of:

  1. In both macros there are two actions coloured red. The first of these specifies the folder you want to save to/retrieve from. This should be set to the same in both macros.
  2. The second coloured action is a regular expression that lets you select which KM variables you wish to save/retrieve. I have set it to .* which means everything (i.e. all your variables) in regex terms. If you set it to, for example, Test that would mean only variable names that contain the literal string "Test" will be acted upon. If you're unsure about regular expressions, I would avoid making any changes to this. In any case, you could use it to selectively save certain variables and, by using a different value in the retrieve macro, you could use it to retrieve a different set of variables.
  3. I have not assigned triggers to these macros and they are uploaded in a disabled state. I would advise that you place them in a Macro Group that is only active for the Keyboard Maestro app.
  4. The Save macro will create the target folder for you if it doesn't already exist. The Retrieve macro will stop and display an error message if the target folder does not exist.
  5. These macros are not beginner-level and the Retrieve macro uses a "trick" to indirectly reference the names of variables. I offer no further explanation of their operation but you will learn a lot by looking at them and understanding them.
  6. I tested this by creating a variety of variables and just played around with all kinds of combinations of target folder/regular expression and everything seemed OK. BUT - I offer no guarantees that it will work correctly for you since your setup is different to mine.
  7. Tested under macOS 10.14.6. Keyboard Maestro version 10.2
  8. Use these macros at your own risk.

If you have any feedback, feel free to offer it.

3 Likes

Thank you both!
@tiffle I was able to make this work quickly and easily.
I am amazed.
Thanks again!

4 Likes

Keyboard Maestro is amazing – and so is our online community...

:sunglasses:

5 Likes