How to save current mouse location to variable

I have this macro:

I need to modify it so that at end of these 3 actions it goes to original location it started with but can't do it as I don't have the location. How to get it?


Here's an action pair that does this. By adding the first action at the beginning of your macro, and the second one at the end, it will finish off by return your mouse to the location where it was at when you triggered the macro.

EDITED to reflect @griffman's apt suggestion below:

Mouse Return to Start.kmmacros (1.5 KB)


Just a minor recommended change to @Alexander's fine solution: Unless you need to keep that stored location for use in other macros, I would recommend using a local or instance variable, both of this will be cleared when the macro completes—there's no need to keep its value around if you don't need it elsewhere.

Preface the variable name with either instance or local, and it'll clear out at the end of the run. The linked page explains the differences; I use local almost all the time, unless I need a variable in a sub-macro (instance) or to stay around when the macro is done (global).

It may seem a minor thing now, but by using instance and local variables by default, you won't wind up with a massive list of global variables.



Or you can just set your variable to the KM token %CurrentMouse%