Show Desktop, if Desktop switch to previous application

There is a really cool action in BetterTouchToll to show Desktop Space :

I would love to improve it if I can where it would do something like this :

Can I do that for this?

Thank you for any help on this.

If I understand you correctly, it should be easy:

  • IF Frontmost App = “Keyboard Maestro” THEN
    • Type Keystroke ⌘H

⌘H is (or should be) available for all apps to hide the app.

Keyboard Maestro should not play a role here at all. This action should show me my ‘Desktop 1’ screen

And if I am already in Desktop 1 and I came from some full screen app, pressing the trigger again will bring me back.

Can such thing done? It’s a small thing but would be quite nice to have.

Sorry, I don’t understand your requirements. I was just following the screenshot example you provided, where you were Activating “Keyboard Maestro”.

If you post the exact steps that you do manually to achieve the desired result, maybe I can understand better.

There is a hotkey you can set in Mission Control to switch to 'Desktop 1'

I would like to replicate and extend it where if I press the hotkey again, it will go the application I went from. If such thing can be done of course. :slight_smile:

1 Like

Apple have not made any control of the Spaces API publicly available, so Keyboard Maestro does not attempt to control the anything related to Spaces.

You may be able to simulate the keystroke you have configured.

OK, give this a try. It has only had very limited testing, so it may contains bugs and/or you may need to adjust. You will need to assign the macro trigger of your choice.

###MACRO: Toggle Desktop Space [Example]

Toggle Desktop Space [Example].kmmacros (5.5 KB)

@peternlewis, I could not find a KM action to activate an app using the app name in a KM Variable, so I had to write this short AppleScript:

tell application "Keyboard Maestro Engine" to set appName to getvariable "AppBeforeToggleOn"
tell application appName to activate

Did I miss the KM Action? Or must it be one via script?

Generally, Keyboard Maestro uses menu selection to specific an application, and thus there is no option to specify the application with a variable - this is true all across the many uses of application selection in Keyboard Maestro, so there is no easy or obvious way to resolve this (mostly it is a UI issue).

So yes, a script is necessary.