How to test for a Space (Mission Control)?

I have set up 7 Spaces that I can access via CMD+1, ..., CMD+7.

Q: Is there a way to verify that I'm in Space #1?

Background:
I have a macro that activates an app. To make sure that it will be running in Space #1, I simulate CMD+1 first. However, sometimes the app will be launched in another Space.

Hi @ALYB. The short answer is there’s no Keyboard Maestro action, AppleScript, or shell script method to determine the Mission Control Desktop Space (unless you install a third party utility).

The long answer is here…

1 Like

I thought I solved this last year. Check out Desktop Images Macros

This is not entirely true. This is the maximum number of spaces that can be configured in the OS Settings > Keyboard > Shortcuts, is 16 and if you only have one screen, that is the max you can create, too.

I currently have 21 spaces active because I originally configured them with an external monitor, and when I unplugged the monitor, nearly all of them were available on my laptop. The exception is that all windows on the first screen of the monitor get moved to the first screen of the laptop and what had been the first monitor screen is now unavailable. On the laptop alone, I cannot add any more spaces. If I plug in my external monitor, then I can add spaces, my guess is up to 16 per screen, I haven't tested it because I haven't needed it. I predict that if I then unplug the monitor, I'll have 31 spaces on my laptop. One of these days, I'll try it.

The best tool I've found for managing spaces has been the free app Current Key Stats, but it is no longer available due to the developer becoming a father and not wanting to port the system to the latest versions of the OS. Just too much work for a free app. He made it work by creating an invisible app on each screen and then getting the OS to switch screens by making the appropriate app window active.

Because he's no longer supporting it, (a few months ago he was putting it up on the app store for one day at a time, on request via Twitter), I would love for him to put it on GitHub or for someone (e.g., @peternlewis) to buy the rights to it and integrate it with some supported product (e.g., Keyboard Maestro). But that's just a dream right now.

Hi @August. I stand corrected. I could have said:

The practical limit* is 16 Mission Control Desktop Spaces.

*There are ways to exceed 16, however, due to limitations with macOS, this macro set is configured to manage 16 or fewer.

Hi @ikenassi ,

I've done some digging in your macros and I haven't found where there is an answer to the OP question. Probably I don't understand your macros well enough yet. Could you point me to where you do this?

I currently have 21 desktop spaces and would like more. I have not figured out a way, using just KM and AppleScript, without relying on a third-party app, to identify which space I'm in, when a space is moved/rearranged, etc.

I've been using a third-party app called CurrentKey, but it is no longer supported. It was free, but the developer was unable to keep it updated so that it could stay in the App Store, he's now a father, and various factors contributed to it being withdrawn. If you contact him on Twitter, he has been willing to put it in the App Store for 24 hours on request, but that is not a solution that I can recommend to others. His system works by placing an invisible app on each desktop. Activating any specific invisible window of that app switches desktops. Seeing which window is foremost tells him which desktop you are in. Etc.

But I haven't yet figured out how to achieve the same thing using only KM and AppleScript. I believe it "should" be possible, but it's currently below my skill level.

If you think your Desktop Images can help, I would appreciate pointers to the appropriate places. Can you, for instance, determine what image is the background on the current desktop? If every desktop had different wallpaper, that might give useful information.

Thanks,
August

Look at my desktop initialization macro. It counts the desktop spaces on all screens. I do not identify which space is the current one, nor do my macros care if/when they are rearranged. Sorry.

But perhaps you can search for a found image on the spaces you’re interested in.

Also, you should familiarize yourself with the keyboard shortcuts to move to specific spaces. In my case, ^0 and ^1, the keys of which are defined in system preferences -> Keyboard -> Shortcuts -> Mission Control

Hope that helps. I’ve been using my desktop wallpaper macros for a couple of years now since the number of available jpegs I can use as desktop wallpapers have increased dramatically during the pandemic.

Thanks. Yes, I’m familiar with the keyboard shortcuts and I find them less than useful. They top out at 16 spaces and I currently have 21. With more than 3 or 4 spaces, it’s hard to remember the correspondence between function and numerical location.

I use the free app CurrentKey to assign names to spaces and switch by name from a menu (either KM’s or CK’s) or assigned mnemonic hot key that —very importantly — doesn’t change if I rearrange the order of the spaces, which I do regularly.

Unfortunately, CurrentKey has been withdrawn because the developer doesn’t have time for it anymore. So I’m banging on the idea of being able to approximate that functionality in KM.

I have found a free app on GitHub called WhichSpace, which puts a little numeric icon in the menu bar to tell you which Desktop Workspace you are in.

Here's the upper left corner of my screen, while I'm on Desktop #20:
image

And here is Desktop 20 shown in Mission Control:
image

As far as I can tell, the developer has not exposed this in any kind of API where you could query for the space number, but it's always in the same place on the screen, so KBM could do image matching in a very small area to quickly determine which space you're in.

Personally, I'd rather do it programmatically, with a numeric or string answer to a query, but image matching is a viable workaround.

1 Like

So it turns out that @_jims actually gave me that in February, but it didn't stick.
(The preview here is poorly formatted; follow the link to see it in a readable form.)

1 Like