MACROS: Desktop Spaces • Macros to Improve Navigation and Window Management, v3.0

I finally got around to "upgrading" from Monterey to Sonoma recently, and the macro set seems to have become very unreliable since.

I keep getting "WhichSpace was unable to return the Desktop Number" errors, which occur when %ActionResult% is not "OK". However, I added a bit to the error message to display the value of the variable:

image

…and it is "OK", as the text at the bottom of the dialog shows »OK«.

image

The errors are intermittent, but usually editing something in KM fixes it for a bit.

I'm on KM 11.0.2 and the 2023-10-27 version of the macros. This feels like a KM bug to me (unless WhichSpace has started returning some bizarre UTF-8 invisible characters in its response!) — but is this happening to anybody else?

Hi, @Unikitty, thanks for the message.

I've been using Sonoma for many months and have observed this issue two or three times. Unfortunately, even when it occurs, it hasn't been consistent; it has always been addressed by a log out and back in.

If this continues for you, @Unikitty, I'll do my best to help!

Thanks, Jim — it is continuing to annoy me. It seems to be timing out on this step:

image

I've got to admit, I'm not sure why it needs to get the space number in order to change space. If I change from space 1 to space 2, it just needs to send the relevant keypress. If I move a window from space 1 to space 2, it just needs to grab the window, send the relevant keypress, and let go of the window. I can see why you'd want to get that for things like "go to previous desktop", but I never use those — just "change space" and "move window".

I think I would prefer a "lite" version which just changes space and moves windows, and doesn't need WhichSpace at all, TBH — I've disabled everything in "sub — Go to Desktop N" except for the execution of "sub — Type Keystroke for Switch to Desktop N" and the pause and it's now reliable for space switches and window moves.

Hi, @Unikitty. Sorry to hear that. Obviously it's difficult to troubleshoot when I cannot duplicate your issue.

If you are interested in trying to resolve this, I suggest you download this test macro:

Download: Test WhichSpace.kmmacros (6.5 KB)

Macro-Image


When I run it, WhichSpace, returns the value in less than 200 ms. If your mac is approaching 2000 ms, then you could change the timeout of the AppleScript action in sub—Get DesktopNo. It's currently set to 2 seconds.


I use that often.


As I mentioned, I move to the previous desktop often. I also move windows to the previous desktop frequently. But if your modification is addressing your requirements, that's great.

Thanks — currently I'm getting under 350ms and usually around 200ms, so it's not that. Maybe the next macOS update will fix it (or make it worse!)

I've sent you a PM with a test version of two of the macros that might help us determine the root cause of the problem.


Keyboard Maestro Version 11+ Required

I've updated the OP with Version 3.0 of Desktop Spaces • Macros to Improve Navigation and Window Management:

Summary of Improvements

  • Macros Go Left a Desktop (& Move Window Left a Desktop) and Go Right a Desktop (& Move Window Right a Desktop) have been improved:

    • While holding the modifier (default Control ⌃), if the right arrow or left arrow are tapped, the display is moved directly that many Desktop Spaces. For example, if you are viewing Desktop 4 and press and hold Control and tap the right arrow three times, the display will be moved directly to Desktop 7.

    • In contrast, while holding the modifier, if the right or left arrows are held down, the display will be moved right (or left) until the arrow key is released. In this case, all Desktops between the starting point and the ending point will be briefly visible. This method is likely useful if you are searching for a particular window as you are moving through the Desktops.

    • Optionally, when moving a display and window, the display can be returned to the original Desktop Space. Two methods can be used to achieve this optional behavior:

      1. via hotkey: hold down the modifier keys and tap the hotkey integer twice.

      2. via the Desktop Spaces palette: when clicking the palette item, hold down the Control (⌃) key.

  • With some limitations, the macro set can now be used without WhichSpace . If it is not installed and running, the Desktop Space Number will not be visible in the macOS menubar. Also, tracking of the current and previous Desktop will be temporarily inaccurate if a Desktop change occurs outside the control of these macros. For example:

    • three-finger swipe left or right on a trackpad

    • Mission Control Desktop Spaces is displayed and a Desktop is selected

    • a macOS application is opened, or activated, and an automatic Desktop change occurs

  • The Desktop Space palette has been annotated to indicate items that can be optionally Control (⌃)+clicked and hotkeys that can be tapped twice [2t] or multiple times [mt].

  • Version 3.0 of this macro group includes other improvements detailed in the installation READ ME and within the comments of the macros.

1 Like