Switch to Designated Apple Desktop Space Running Application

I have a number of apps set with a KM macro such as Control Z to jump to InDesign. I have all my apps assigned to a specific Desktop Space in Mission Control.

Is there a way to write into the KM macro the ability to switch to the designated Space when the shortcut is triggered?

Unfortunately Apple have not released any public API for controlling or dealing with Spaces. As such Keyboard Maestro does not have any facilities for directly relating to Spaces.

About the only thing you can do is use UI actions to move spaces.

Has this situation changed? Is there anything in any newer version of KBM in the past 18 months to help with this issue?

If not, there is a free application called Current Key (https://currentkey.com/) that allows you to set a unique hotkey as well as a unique status bar icon for each desktop. I have 8 desktops in my MacBook screen and 12 in my external monitor. I have hotkeys for each. (That's been tricky finding keys that don't do other system things or app things, depending on the active app. I'm planning on using KBM to expand the range of hotkeys available for this while still keeping them more or less mnemonic as well as typable with one hand by using a "Conflict Menu".)

I've tested it and I can have KBM just invoke the CK hotkey for the desktop I want and when it's triggered it pops me to that desktop/workspace.

The most recent version of CK now includes what the author calls "Bi-directional AppleScript support". Theoretically (I have not tested this yet), I can use that to both set and determine what desktop I'm in from within KBM scripts. The CKS info is at https://currentkey.com/room-change-alerts/. Here's an image from that page:

I'm starting to imagine a KBM script that would, on each desktop, open a graphics editor (e.g., Inkscape) on the specific background desktop image for that desktop where I would have an image on the one layer and than have an overlay of text and graphics.

That would let me put a text name for the desktop over the image of the ocean (or whatever) and mark the space to indicate what each region of the screen is for, reminders of what apps I use for what and where their windows live when they are open. Perhaps KBM could be used to set that up that organization too.

That would allow the desktop background to be editable as my projects change or my app workflow evolves to help make my desktop background be a functional part of my work. It would help me use the entire desktop space more like a project whiteboard. By invoking the same hotkey on each desktop, I could edit the background image and its overlay that is used on that desktop.

BTW, Current Key was formerly called Current Key Stats from the fact that it will track statistics of how much time you spend in each desktop in each app, so you can use it for billing, timesheet, or personal productivity tracking. I don't use that feature.

I am using this AppleScript, but I refuse to believe that there isn't a better way :slight_smile:

tell application "System Events"
	tell application process "Dock"
		tell list 1
			click UI element "Google Chrome"
			delay 0.01
			click UI element "Google Chrome"
		end tell
	end tell
end tell

Depending on your settings in System Preferences > Mission Control, you need a single or a double click.

@Printdevil, @August and @jhein, you might find this useful: Desktop Spaces • Macros for Navigation and Window Management

Thanks @_jims. I may well be copying your logic.

I found the Apple default of referring to Desktop Spaces by number to be confusing, especially since I sometimes like to rearrange the order of my Desktops to suit what I'm working on.

A while ago I did a Google search on how to give Apple Desktop Spaces names and I found the free app, CurrentKey Stats. (The name comes from the developer using it to compile statistics on how much time he spends in each Desktop. That's not my use case.)

He has a very robust set of tools for referring to different Desktops by name, where the names persist when the Desktops are rearranged. He also has AppleScript hooks to do things like get the list of current names, move focus to the named Desktop, etc.

I hope this helps,