Going Back to Previous Application/Window

Hi everyone!

I just started using Keyboard Maestro and I love it! I've just setup an action that goes to a specific application and does some actions there and after that minimize the application.

What I want to achieve is that Keyboard Maestro makes me go back to the application/window I was at when starting the action. So for example:

  1. I press the hotkey
  2. The action begins to run. Keyboard Maestro goes the application.
  3. Keyboard Maestro executes some actions
  4. Keyboard Maestro minimized the application.
    5. Keyboard Maestro opens the application I had open before I pressed the hotkey.

Thanks for helping!

Use the Activate Last Application action

That should do it!

As @tiffle says, if you're only going to one application for this macro, the simplest solution is to add an Activate Last Application action at the end of it. If the macro involves switching between multiple applications, or you just want to be completely sure, you can set a variable at the start of the macro that records the current app's name, then use that variable at the end to activate the original app:

1 Like

This worked, thanks!

I can't seem to get this to work correctly.

I'm switching to an application and clicking the mouse and would like to maintain the mouse position and switch back to the previous app. Everything works fine except it doesn't always switch back to the previous app. It seems like it's switching to the previous app really quick and then switches back to Pocket Casts again.

I also tried setting the application name as a variable and the same results happen it seems. Anything I'm doing wrong?

try adding some pauses, or try using the method gglick posted above:

@gglick's method didn't work for me either. Adding a pause right before the "Activate Last Application" seems to work. I set it to "1 hundredths" and that works and is quick enough to not even notice. Thanks!

1 Like

It looks like you figured out a solution but here's one I use quite extensively that may work for you as well. If nothing else it gives you options.

Basically the first set of actions record which application and specific window are at the front, sets them to variables and minimizes it.

The second set (which would be placed after the rest of the macro runs) uses an AppleScript to recall both the application and specific window.

I've attached the macro here (as well as a screenshot so you can see what it does beforehand) if you want to try it.

Minimize current application front window, execute macro, then unminimize previous front window.kmmacros (6.8 KB)