Get Mouse Position, Run Other Actions, Then Return Mouse Pointer to Same Position

Frankb, there is no other way to change an exact zoom level in Lightroom that I know of, other than pointing and clicking (but I am no expert). I like the idea of a macro because I tire of the eye-hand exercise that Lightroom forces me to do so much. I am going to try these macros on a stream-deck or a tour box.

tiffle, I didn't expect the restore mouse position would work, but it did! Wow. What a cool thing to learn. Thank you!

1 Like

I have found this explanation...

To zoom in quickly and easily, you can use this handy keyboard shortcut: CMD and + key . To zoom out, use the CMD and the - keys. If your first zoom doesn't get you to the magnification you desire, do it again; it will zoom in closer each time.

Ah, but it probably doesn't give you the exact zoom level you want.

Wow Frankb, you are right! What an easy way to change the zoom level.

I guess I should google things, before I make things harder than they need to be. (Kind of typical for me. :yum:)

I know I'll need Keyboard Maestro in other situations where I may not have a keyboard shortcut, so this exercise was still very useful for me. Thank you for your help.

Probably because these questions often involve multiple "move and click"s -- while you can do each of those as a "move, click, restore" you get annoying extra pointer movements.

It doesn't work like that. Your mouse_position variable is set to the evaluation of the %CurrentMouse% token at the moment the action is executed -- since there's no "auto-update" and you don't set mouse_position to another value during your macro it should work...

But it looks like you've extra text in the field, after %CurrentMouse% -- see how the action's name has ... after the %, indicating that there's more to show than there's room for? So mouse_position is an invalid value for coordinate-setting when you come to use it in the last action. Make sure you've no rogue spaces or linefeeds in there and that should solve your problem.

I do not know many apps. But I don't know any app that doesn't have a shortcut to zoom.

This reminds me of what @Nige_S and @noisneil always say, "Don't just explain what you want to do at the beginning, explain also why you need it." Sometimes there are very simple solutions. :slightly_smiling_face:

2 Likes

Nige_S

You are correct. I had a "space" and a line feed after %CurrentMouse%. I removed them and the macro worked.

I appreciate your expertise. You are amazing!

This another lesson learned for me.

1 Like

Great advice. Thanks. I'll try to keep it simple and explain my need. It would make my life easier. :upside_down_face:

It remains to mention that here once again the fundamental problem of the KM becomes visible.

If you search for "mouse" in the actions, you get this result

If there were additionally these two actions, no questions would arise also with beginners

  1. save current mouse position.
  2. restore saved mouse position.

And this is only one example of many. The developer of KM has asked several times to be told what would make his app easier for beginners, but he apparently finds such things pointless. :slightly_smiling_face: :man_shrugging:

1 Like

Don't stop there!

There are few fundamentals that will make life in KM easier...

The manual is very good. You don't have to learn it word for word, but have a quick skim so you can understand the concepts and, importantly, know where to go back to later when you have questions.

You use Actions to do things. There are a lot of Actions, most of them have multiple options, and most of them can use values that you can provide in some way.

You use Tokens and Functions to get values. You can store these values in Variables, save them for later or manipulate them with Filters or Search and Replace (text), Calculations (numbers), and in other ways -- and then use them in later Actions.

Branching, like "If Then Else" or "Switch/Case", and the various looping actions like "Repeat" and "While" add a lot of power, but using them relies on everything above, so concentrate on the basics first.

As a wise person never actually said: "Give a man a 'Save current mouse position' action and he'll be able to save his mouse position. Teach him how to roll his own using KM fundamentals and he'll be able to automate anything [1]".

But the most important fundamentals of all are:

  1. Work out what you want to do
  2. Break that down to the simplest steps you can
  3. Try and work out how to do each step using KM's Actions, Tokens, etc
  4. If stuck for more than 5 minutes, don't beat yourself up -- we've all been there. Post your problem here, following these guidelines and ideally uploading a sample macro, and help will soon be at hand.

Welcome to KM, and welcome to the Forum!


[1] Some hyperbole may have been employed in the making of this statement. The value of your macro can go down as well as up, etc, etc...

1 Like

Frankb, I was surprised that the actions you mentioned aren't a part of KM. Probably too basic for experienced programmers, but us beginners would appreciate them.

The last time I tried to program a computer was about 45 years ago, on an Apple ][ computer in basic. I never took a class, but I could do For Next Loops and print "Hello World" on the screen. Applesoft Basic made my head spin, but I did learn some of the logic of programming. I knew I could never be a programmer.

If the developer of KM could make it easier for non-programmers to create simple macros by providing some simple pre-made actions (even knowing that experienced programmers don't need them), I think the appeal for KM would grow, as not everybody is a programmer. Many people have some simple programming skills and they might be excited to try KM if it was a little easier to get started.

I have found your help and those of others really terrific, and I will plod along knowing there are helpful people here willing to lend a hand. Hopefully KM can be made a little more user friendly for beginners in the future :slightly_smiling_face:

Nige_S,

Thank you so much for the words of encouragement.

I'll study the manual, and look for at sample macros to learn more.

I appreciate the explanations of actions, tokens and functions, variables and such.

My needs are pretty simple, but I like to learn so this will be interesting for me.

Thanks again

As a wise man once said, "Gee, I wish there was a delay action :nerd_face:" (my next thing to learn)

You are totally right, a wise person would never say something like that :wink: What a wise person would actually say is, "Give a man as many predefined actions as possible, and he will use them to build the most complex things without having to learn other fundamentals, because these are the fundamentals."

That is exactly how it is. But simple truths cannot enter complex thinking brains.

And again you got that exactly right. You could explain to the pros that a simple action like "save current mouse position" doesn't take anything away from them, because KM still offers the possibility to solve it in a complex way, but they wouldn't like it even then.

This is really true. The friendly pros here unfortunately have no idea what beginners need, but they are always ready to help. And that's much more than you can say about other forums. So @Donald just ask and you will receive :slightly_smiling_face:

Well - you already created them, but here they are again for you...

image
Save Current Mouse Position.kmactions (592 Bytes)

image
Restore Saved Mouse Position.kmactions (583 Bytes)

Although this is a bit of a cheat, just import these two actions into KM and then add them to Favorites (KM Menu > Actions > Add to Favorites) so they'll be readily available whenever you want.

KM can be made simpler - you just have to put in the effort to become an unfortunate pro! Enjoy!

tiffle,

That is a great tip. I put those actions in my actions favorites. Thank you for uploading them so they can be downloaded by myself and others.

Thank you!

1 Like

That's the problem with making KM simpler - it can lead to complications and I must assuage my feelings of guilt for posting something too simple!

Here's something to consider: suppose you have two macros that both use those saving/restoring actions. What happens when both macros run simultaneously? They might interfere with each other because they both use the same global variable for the mouse position. So while one macro runs and saves the mouse position, the other macro comes along and also saves the mouse position; then when the first macro restores the mouse position it actually uses the position set by the second macro. In other words: WRONG!!

To prevent this from happening you have to understand the difference between global and local variables: when you use a global variable called "X", say, in a macro, that same "X" can be seen, used and updated in any other macro. This makes global variables useful for passing information between macros. Global variables exist separately from macros and even retain their values when your Mac reboots!

Local variables on the other hand are "hidden" from every macro except the one they are first used in. In simple terms a local variable called "Local_Y" in one macro is completely independent from the same-named local variable in any other macro. So changing "Local_Y" in a macro does not affect the value of any other "Local_Y" in any other macros you have. And when your macro finishes, or your Mac reboots, "Local_Y" disappears...as do every other local variable.

How does that affect the mouse saving/restoring actions I previously posted? Well, here is a matching pair that works safely without interfering with any others in any of your other macros.

image

Local Save-Restore Mouse Position.kmactions (941 Bytes)

The only difference is that they now use local variables meaning you can sprinkle these actions liberally around your macros without them interfering with each other.

Sometimes you might actually want to save the mouse position and use it in another macro - in which case use the global variable version of these actions I originally posted.

This whole post illustrates a peculiarity that perhaps escapes most users of KM: even when KM provides simple actions you most likely still need to have a detailed understanding to make full use of them. And that's where @Nige_S's brilliantly straightforward summary in post 18 comes into its own for those just starting out with KM.

3 Likes

Beautiful explanation. Now I got a clearer understanding.

What do you mean by 'disappears'?

Suppose I uninstall KM from my Mac. Install again, would the variable "Local_Y" retain its respective value in each macro?

Literally that. Local_Y only exists while the macro is executing.

In fact it goes further -- local variables are particular to each instance of a macro. So if you fire off "Macro A", then trigger it again before the first instance has completed, each instance of "Macro A" will have its own Local_Y with its own, segregated, value.

Have a look at the Variables section of the manual for more about the different types and their scope.

2 Likes

tiffle,

That is an excellent explanation of Global VS Local variables. I had no idea that variables could be passed from one macro to another. I was happily surprised to learn global macro values are retained, even when the computer is rebooted, and that local variables stay with the original macro, even if other macros are using local variables with the same name. I am amazed by this program, and even more amazed by your clear explanations. Thank you so very much.

Thank you for uploading the local mouse position actions. I'll add them to my favorites, and I will have a clear understanding of which action ( Global vs Local ) to use appropriately.

1 Like

Nige_S,

Thanks you for clarifying how local variables work.

It is amazing to me more than one macro can be running at the same time, and have variables with the same name in different macros not interfere with each other, as long as they are local variables. I can see how global variables with the same name and running at the same time would cause a real mess.

Thanks for your helpful information.

1 Like

Thank you, too, @Donald and @fluid_eye and thanks @Nige_S for appearing when I “disappeared”! Much appreciated.

1 Like