Restore Saved Mouse Location?

I have a KM macro that performs a number of actions in one app (idoceo), then opens another app (MS Word) and ends, allowing me to edit text. Then I have another KM macro that saves and closes Word and brings the first app back to the front. I would like to be able to store the mouse location from the first KM macro (first app) in a variable, then when I return to that first app, restore the mouse location.

I can set up separate KM actions to do the two desired steps (store, restore), but they don't work as intended, possibly because KM treats the stored variable as a local variable that gets deleted when the action ends. I need to store that mouse location globally so that it can be subsequently used elsewhere in another macro.

Is that possible? Is there a way to store the mouse location somewhere in KM so it can be used in other KM macros?


You can do the following


As long as the variable does not start with Local_, Instance_ (case insensitive), it will be treated as global stored variable.

1 Like

This example shows how much easier it would be if KM had predefined actions for such things. :slightly_smiling_face:

"Save current Mouse position"


"Restore saved Mouse position"

@pauhana would have found them and would not have had to ask. :man_shrugging:

Edit: However, then he would have had no contact with the very helpful people on this forum. Everything has advantages and disadvantages :wink:

1 Like

Just remove the Local__ prefix and it becomes a global variable.

(Oops, just realised @macdevign_mac beat me to it.)

I'm assuming the last action is an alternative to the second one but can't think of a reason why it might be preferred.

Except they would, because the problem wasn't with them getting/setting the pointer position but with having that value persist so it could be used in a different macro.

You could post a pack of commonly used favourites that new users can download and install if you like. There's no real difference between a favourite and a "predefined action". However, I feel that the forum is an extension of the app, so for simple things like this, it's usually only a couple of minutes' work to make them yourself, and it's a good way to learn about the logic of variables etc. As you say, advantages and disadvantages.

Searching the forum is frequently worth the effort.

Search results for 'restore mouse location' - Keyboard Maestro Discourse

Sorry for the long radio silence... end-of-semester madness here in Japan.

The solution turned out to be quite simple. Following Macdevign_mac's suggestion, I set a global variable for the mouse position in one macro. I could then restore that mouse position in another macro, and it works perfectly!

I agree with FrankB, it would have been easier if KM had a predefined action for mouse position, but then, as he also noted, I would never have 'met' all the helpful people in this forum.

As I get to know more about KM's incredible macro capabilities, I'm sure I'll be coming back for more help. Again, thanks, everyone!