Desktop Spaces β€’ Macros for Navigation and Window Management

On my MacBook Pro I use up to 15 Desktop Spaces. With several, I've assigned applications to specific spaces, e.g., I've assigned Messages to Desktop 3. With the relatively small footprint of a laptop, the combination of multiple Desktop Spaces and keyboard shortcuts greatly reduces the time and mousing required to manage windows.

Although space-assignment for some apps is certainly beneficial, there are times when windows from these apps need to be visible on other spaces. Movement of such windows with native macOS features is somewhat clumsy, and certainly not done quickly.

Keyboard Mastro, and this set of macros, can greatly assist with this macOS shortcoming and other common Desktop Space tasks even if only a few Desktop Spaces are being used.

Note that all macros below will install in a disabled Keyboard Maestro group named .sys Spaces. The individual macros will be enabled, but they will not be available until the group is enabled.


Macro: Move Window to a Space

The purpose of this macro is to move the active window to a Mission Control Desktop Space.

More
  Move window to Space 1           βŒƒβŒ₯1
  Move window to Space 2           βŒƒβŒ₯2
  Move window to Space 3           βŒƒβŒ₯3
  Move window to Space 4           βŒƒβŒ₯4
  Move window to Space 5           βŒƒβŒ₯5
  Move window to Space 6           βŒƒβŒ₯6
  Move window to Space 7           βŒƒβŒ₯7
  Move window to Space 8           βŒƒβŒ₯8
  Move window to Space 9           βŒƒβŒ₯9
  Move window to Space 10          βŒƒβŒ₯A
  Move window to Space 11          βŒƒβŒ₯B
  Move window to Space 12          βŒƒβŒ₯C
  Move window to Space 13          βŒƒβŒ₯D
  Move window to Space 14          βŒƒβŒ₯E
  Move window to Space 15          βŒƒβŒ₯F
  Move window left a space         βŒƒβŒ₯←
  Move window right a space        βŒƒβŒ₯β†’

The macro completes the move by invoking a click-and-hold on the window followed by typing the keystroke that moves to the target space. Then after a short pause, the click is released and the mouse is returned to its original position.

PREREQUISITE SETTINGS
This macro requires up to the 11 native macOS keyboard shortcuts below to be set (System Preferences > Keyboard > Shortcuts > Mission Control). The first two must always be set. As up to 9 Desktop Spaces are added, shortcuts ^1 through ^9 must be set. For Spaces 10 to 15, no additional shortcuts are required.

  Move left a space                βŒƒβŒ₯⇧Q
  Move right a space               βŒƒβŒ₯⇧W
  Switch to Desktop 1              βŒƒ1
  Switch to Desktop 2              βŒƒ2
  Switch to Desktop 3              βŒƒ3
  Switch to Desktop 4              βŒƒ4
  Switch to Desktop 5              βŒƒ5
  Switch to Desktop 6              βŒƒ6
  Switch to Desktop 7              βŒƒ7
  Switch to Desktop 8              βŒƒ8
  Switch to Desktop 9              βŒƒ9

ACKNOWLEDGEMENTS
Note: The logic in this macro was taken from macro: Move Frontmost Window to a Different Space

For more information, refer to @Tom's forum post: Move Frontmost Window to a Different Space - Macro Library - Keyboard Maestro Discourse

Three modifications were made for this macro:

  1. Expanded to accommodate up to 15 Desktop Spaces

  2. Changed the βŒƒβŒ₯Left Arrow and βŒ₯Right Arrow actions. For the rationale, see Peter Lewis’ comment in the forum post.

  3. Added logic to exit immediately if the shortcut is invoked in a space without windows

Due to the above changes, the name was changed from Move Frontmost Window to a Different Space to Move Window to a Space.

TESTED WITH
β€’ Big Sur, v11.2.1
β€’ Keyboard Maestro, v9.2
β€’ MacBookPro16,1

VERSION HISTORY
1.0 - Initial version
1.1 - Added back triggers: βŒƒβŒ₯← and βŒƒβŒ₯β†’. They were mistakenly removed before v1.0 was uploaded.

 

Move Window to a Space, v1.1, 2021-02-25

DOWNLOAD Macro File:
.sys Spaces Macros.kmmacros (272 KB)

Although not required for the operation of any other macros in this post, these two simple macros, in combination with the native macOS keyboard shortcuts, can be used to navigate a Desktop Space left (βŒƒβ†) and right (βŒƒβ†’), respectively.

Move Left a Space, v1.1, 2021-02-26

  Move left a space                βŒƒβŒ₯←

DOWNLOAD Macro File:
Move Left a Space.kmmacros (4.7 KB)

Move Right a Space, v1.1, 2021-02-26

  Move right a space               βŒƒβŒ₯β†’

DOWNLOAD Macro File:
Move Right a Space.kmmacros (4.7 KB)


Macro: Return to Previous Space

This macro is used to return to the previously displayed Mission Control Desktop Space. For example, if Space 5 is visible and ^2 is used to move to Space 2, ^Return will return to Space 5. Since a second ^Return will move back to Space 2, this macro makes it easy to toggle between two Desktop Spaces, even if they are nonadjacent.

More
  Return to Previous Space        βŒƒReturn

Note 1: Fundamental to the operation of this macro, the current Desktop Space number must be determined. This value is not available using native Keyboard Maestro actions because, according the this comment from @peterlewis, the space number is not available via a public API. Therefore, a third-party menubar open source tool named WhichSpace and AppleScript are required for this macro. See below for more information.

Note 2: This macro records a space change by detecting if the focused window title changes. Generally this works well because a user is typically toggling between spaces to use different applications or at least different windows within the same application. If however, a user changes to another space that has the same foreground window active, the previous space will not be updated, thus this macro may return to an unexpected space when it is invoked by ^Return.

PREREQUISITE SETTINGS
This macro requires up to the 11 native macOS keyboard shortcuts below to be set (System Preferences > Keyboard > Shortcuts > Mission Control). The first two must always be set. As up to 9 Desktop Spaces are added, shortcuts ^1 through ^9 must be set. For Spaces 10 to 15, no additional shortcuts are required.

  Move left a space                βŒƒβŒ₯⇧Q
  Move right a space               βŒƒβŒ₯⇧W
  Switch to Desktop 1              βŒƒ1
  Switch to Desktop 2              βŒƒ2
  Switch to Desktop 3              βŒƒ3
  Switch to Desktop 4              βŒƒ4
  Switch to Desktop 5              βŒƒ5
  Switch to Desktop 6              βŒƒ6
  Switch to Desktop 7              βŒƒ7
  Switch to Desktop 8              βŒƒ8
  Switch to Desktop 9              βŒƒ9

OTHER DEPENDENCY
The free open source application WhichSpace must be running. The author of WhichSpace, George Christou, kindly told me that the value displayed by WhichSpace could be returned using the AppleScript included within this Marco.

LIMITATIONS
As configured, this macro is limited to Desktop Spaces 1 to 15.

TESTED WITH
β€’ Big Sur, v11.2.1
β€’ Keyboard Maestro, v9.2
β€’ MacBookPro16,1

VERSION HISTORY
1.0 - Initial version
1.1 - Updated the macro name in this comment from Return to the Previous Space to Return to Previous Space. There is no functional change to this macro.

 

Return to Previous Space, v1.1, 2021-02-26

DOWNLOAD Macro File:
Return to Previous Space.kmmacros (41 KB)


Macro: Move Window to the Previous Space

The purpose of this macro is to move the active window to the previously displayed Mission Control Desktop Space.

More
  Move window to Previous Space    βŒƒβŒ₯Return

For example, if Space 5 is visible and ^2 is used to move to Space 2, ^βŒ₯Return will return the active window on Space 2 to Space 5. Since a second ^βŒ₯Return will move the window back to Space 2, this macro makes it easy to toggle between two Desktop Spaces, even if they are nonadjacent.

Note: Fundamental to the operation of this macro, the current Desktop Space number must be determined. This value is not available using native Keyboard Maestro actions because, according the this comment from @peterlewis, the space number is not available via a public API. Therefore, a third-party menubar open source tool named WhichSpace and AppleScript are required for this macro, See below for more information.

PREREQUISITE SETTINGS
This macro requires up to the 11 native macOS keyboard shortcuts below to be set (System Preferences > Keyboard > Shortcuts > Mission Control). The first two must always be set. As up to 9 Desktop Spaces are added, shortcuts ^1 through ^9 must be set. For Spaces 10 to 15, no additional shortcuts are required.

  Move left a space                βŒƒβŒ₯⇧Q
  Move right a space               βŒƒβŒ₯⇧W
  Switch to Desktop 1              βŒƒ1
  Switch to Desktop 2              βŒƒ2
  Switch to Desktop 3              βŒƒ3
  Switch to Desktop 4              βŒƒ4
  Switch to Desktop 5              βŒƒ5
  Switch to Desktop 6              βŒƒ6
  Switch to Desktop 7              βŒƒ7
  Switch to Desktop 8              βŒƒ8
  Switch to Desktop 9              βŒƒ9

OTHER DEPENDENCY
The free open source application WhichSpace must be running. The author of WhichSpace, George Christou, kindly told me that the value displayed by WhichSpace could be returned using the AppleScript included within this Marco.

LIMITATIONS
As configured, this macro is limited to Desktop Spaces 1 to 15.

TESTED WITH
β€’ Big Sur, v11.2.1
β€’ Keyboard Maestro, v9.2
β€’ MacBookPro16,1

VERSION HISTORY
1.0 - Initial version

 

Move Window to the Previous Space, v1.0, 2021-02-26

DOWNLOAD Macro File:
Move Window to the Previous Space.kmmacros (35 KB)


Macro: Move Window to the Current Space

The purpose of this macro is to move a window from another Mission Control Desktop Space to the Current Space.

More
  Move window to Current Space     βŒƒβŒ₯0

When the macro is invoked, a list of running applications will appear in a prompt list. When one of the applications is selected, the macro will move to the Space where the active window for the applications resides. The window will then be moved to the Current Space.

The window move is done by invoking a click-and-hold on the upper-left of the window followed by typing the keystroke that moves back to the Current Space. Then after a short pause, the click is released and the mouse is returned to its original position.

PREREQUISITE SETTINGS
This macro requires up to the 11 native macOS keyboard shortcuts below to be set (System Preferences > Keyboard > Shortcuts > Mission Control). The first two must always be set. As up to 9 Desktop Spaces are added, shortcuts ^1 through ^9 must be set. For Spaces 10 to 15, no additional shortcuts are required.

  Move left a space                βŒƒβŒ₯⇧Q
  Move right a space               βŒƒβŒ₯⇧W
  Switch to Desktop 1              βŒƒ1
  Switch to Desktop 2              βŒƒ2
  Switch to Desktop 3              βŒƒ3
  Switch to Desktop 4              βŒƒ4
  Switch to Desktop 5              βŒƒ5
  Switch to Desktop 6              βŒƒ6
  Switch to Desktop 7              βŒƒ7
  Switch to Desktop 8              βŒƒ8
  Switch to Desktop 9              βŒƒ9

OTHER DEPENDENCIES

  1. The free open source application WhichSpace must be running. The author of WhichSpace, George Christou, kindly told me that the value displayed by WhichSpace could be returned using the AppleScript included within this Marco.

  2. The Activate an Application by Name action, available by a custom Keyboard Maestro Plug-in, by @ComplexPoint, must be installed.

LIMITATIONS
As configured, this macro is limited to Desktop Spaces 1 to 15.

TESTED WITH
β€’ Big Sur, v11.2.1
β€’ Keyboard Maestro, v9.2
β€’ MacBookPro16,1

VERSION HISTORY
1.0 - Initial version

 

Move Window to the Current Space, v1.0, 2021-02-22

DOWNLOAD Macro File:
Move a Window to the Current Space.kmmacros (36 KB)


SUMMARY OF NATIVE KEYBOARD SHORTCUTS AND MACRO HOT KEYS

The macOS native keyboard shortcuts and macros detailed above will enable efficient spaces navigation and window movement. This section includes a summary.

More

Space Navigation

  Move left a space                βŒƒβ†
  Move right a space               βŒƒβ†’
  Switch to Desktop 1              βŒƒ1
  Switch to Desktop 2              βŒƒ2
  Switch to Desktop 3              βŒƒ3
  Switch to Desktop 4              βŒƒ4
  Switch to Desktop 5              βŒƒ5
  Switch to Desktop 6              βŒƒ6
  Switch to Desktop 7              βŒƒ7
  Switch to Desktop 8              βŒƒ8
  Switch to Desktop 9              βŒƒ9
  Return to Previous Space         βŒƒReturn

Navigation beyond Space 9 can be done two ways:

  1. βŒƒ9, followed by the required number of βŒƒβ†’

  2. By opening or activating an application that has been assigned to the space. (This method can be used for any of the 15 spaces.)

Window Movement

  Move window left a space         βŒƒβŒ₯←
  Move window right a space        βŒƒβŒ₯β†’
  Move window to Current Space     βŒƒβŒ₯0
  Move window to Space 1           βŒƒβŒ₯1
  Move window to Space 2           βŒƒβŒ₯2
  Move window to Space 3           βŒƒβŒ₯3
  Move window to Space 4           βŒƒβŒ₯4
  Move window to Space 5           βŒƒβŒ₯5
  Move window to Space 6           βŒƒβŒ₯6
  Move window to Space 7           βŒƒβŒ₯7
  Move window to Space 8           βŒƒβŒ₯8
  Move window to Space 9           βŒƒβŒ₯9
  Move window to Space 10          βŒƒβŒ₯A
  Move window to Space 11          βŒƒβŒ₯B
  Move window to Space 12          βŒƒβŒ₯C
  Move window to Space 13          βŒƒβŒ₯D
  Move window to Space 14          βŒƒβŒ₯E
  Move window to Space 15          βŒƒβŒ₯F
  Move window to Previous Space    βŒƒβŒ₯Return

MANAGING SPACES WITH A PALETTE

If the macros in this section are downloaded and installed (along with the macros from above), the functions described above can be optionally controlled using one hot key (default: ^S) which opens a Keyboard Maestro Conflict Palette.

More

Because it is a little faster, I normally navigate spaces and complete related window moves using the macOS native Mission Control Keyboard Shortcuts and the hot keys defined within the four macros above; but the palette can be helpful for a new user.

TESTED WITH
β€’ Big Sur, v11.2.1
β€’ Keyboard Maestro, v9.2
β€’ MacBookPro16,1

VERSION HISTORY
1.0 - Initial version
2.0 - a) Added a palette macro to launch the new macro above named Move Window to the Previous Space. b) Added palette spacers/labels to annotate the palette entries.

 

Managing Spaces with a Palette, v2.0, 2021-02-26

The following download will replace all of the palette macros from Version 1.0; thus before downloading and installing, move to the Keyboard Maestro group named .sys Spaces and delete all of the macros that are triggered by ^S.

DOWNLOAD Macro Files (36):
sys Spaces Macros.kmmacros (151.6 KB)

3 Likes

Update: Move Window to a Space

Just updated OP with this fix.

1 Like

Updates: Move Left a Space and Move Right a Space

VERSION HISTORY
1.0 - Initial version
1.1 - Changed the Pause to 0.8 Seconds. With a shorter pause, the spaces would sometimes skip two positions when the arrow key was momentarily pressed.

Just updated OP with this fix to both macros.

1 Like

Update: Return to Previous Space

VERSION HISTORY
1.0 - Initial version
1.1 - Updated the macro name in this comment from Return to the Previous Space to Return to Previous Space. There is no functional change to this macro.

New: Move Window to the Previous Space

VERSION HISTORY
1.0 - Initial version

Update: Managing Spaces with a Palette

VERSION HISTORY
1.0 - Initial version
2.0 - a) Added a palette macro to launch the new macro above named Move Window to the Previous Space. b) Added palette spacers/labels to annotate the palette entries.

Just updated OP with these changes and additions.