Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to the Power Users community on Codidact!

Power Users is a Q&A site for questions about the usage of computer software and hardware. We are still a small site and would like to grow, so please consider joining our community. We are looking forward to your questions and answers; they are the building blocks of a repository of knowledge we are building together.

Circulate through spaces on macOS 11

+1
−0

Back in the days of OSX 10.6 Snow Leopard, one could circulate from the last space to the first space, e.g. if one was on the last space and used the keyboard shortcut to go to the next space, it would bring you to the first space.

I asked a similar question for Mavericks at https://apple.stackexchange.com/questions/152768/cycle-through-spaces-in-mavericks , however TotalSpaces2 no longer works on macOS 11 (Big Sur). There is a test version for TotalSpaces3 which mostly works on macOS 11, but it is a bit fragile (frequent crashes).

Is there any other way to bring circulation through spaces back to macOS 11?

History
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

2 answers

+0
−0

Another approach is to use Karabiner-Elements.

As a first step, I created to executable shell scripts, which will switch to the previous/next space using the handy tool SpaceInfo

Space_prev:

#!/bin/zsh
export CurrentSpace=$(/Applications/SpaceInfo/SpaceInfo --active-space)
export AllSpaces=$(/Applications/SpaceInfo/SpaceInfo --total-spaces) 
export NextSpace=$(($CurrentSpace-1))
if [[ $NextSpace = 0 ]] then
  export NextSpace=$AllSpaces
fi
osascript -ss - $NextSpace <<EOF
    on run argv
      tell application "System Events" to key code 17 + (item 1 of argv) using control down
    end run
EOF

Space_next:

#!/bin/zsh
export CurrentSpace=$(/Applications/SpaceInfo/SpaceInfo --active-space) 
export AllSpaces=$(/Applications/SpaceInfo/SpaceInfo --total-spaces) 
export NextSpace=$(($CurrentSpace+1))
if [[ $NextSpace = $(($AllSpaces+1)) ]] then
  export NextSpace=1
fi
osascript -ss - $NextSpace <<EOF
    on run argv
      tell application "System Events" to key code 17 + (item 1 of argv) using control down
    end run
EOF

Then I'm using Karabiner-Elements to set up keyboard shortcuts which will execute these two scripts:

{
    "description": "Next space",
    "manipulators": [
        {
            "from": {
                "key_code": "right_arrow",
                "modifiers": {
                    "mandatory": [
                        "command"
                    ]
                }
            },
            "to": [
                {
                    "shell_command": "/bin/zsh Space_next"
                }
            ],
            "type": "basic"
        }
    ]
},
{
    "description": "Prev space",
    "manipulators": [
        {
            "from": {
                "key_code": "left_arrow",
                "modifiers": {
                    "mandatory": [
                        "command"
                    ]
                }
            },
            "to": [
                {
                    "shell_command": "/bin/zsh Space_prev"
                }
            ],
            "type": "basic"
        }
    ]
}

Caveats:

  • this answer assumes that cmd+number is the shortcut to go to the space of a specific number. If you use another shortcut, you'll need to adjust the code accordingly

  • the animation when cycling between last/first might look counter intuitive. Switching off all animation with the "reduced motion" option from system preferences might be a solution

History
Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+0
−0

One possibility is to use Hammerspoon with the following configuration:

hs.hotkey.bind({ "cmd" }, "Right", function()
    local NextSpace = 1
    for k, v in pairs(hs.spaces.allSpaces()[hs.screen.mainScreen():getUUID()]) do
        if v == hs.spaces.focusedSpace() then
            NextSpace = k
        end
    end
    NextSpace = NextSpace+1
    if (NextSpace == (#hs.spaces.allSpaces()[hs.screen.mainScreen():getUUID()]+1)) then
        NextSpace = 1
    end
    hs.eventtap.keyStroke({ "control" }, string.format("%d", NextSpace))
end)

hs.hotkey.bind({ "cmd" }, "Left", function()
    local PrevSpace = 1
    for k, v in pairs(hs.spaces.allSpaces()[hs.screen.mainScreen():getUUID()]) do
        if v == hs.spaces.focusedSpace() then
            PrevSpace = k
        end
    end
    PrevSpace = PrevSpace - 1
    if (PrevSpace == 0) then
        PrevSpace = #hs.spaces.allSpaces()[hs.screen.mainScreen():getUUID()]
    end
    hs.eventtap.keyStroke({ "control" }, string.format("%d", PrevSpace))
end)

In case one would also like to use mouse/trackpad gestures to circulate through spaces, one can use this newly defined Hammerspoon shortcut in Jitouch

Caveats:

  • this answer assumes that cmd+number is the shortcut to go to the space of a specific number. If you use another shortcut, you'll need to adjust the code accordingly

  • the animation when cycling between last/first might look counter intuitive. Switching off all animation with the "reduced motion" option from system preferences might be a solution

History
Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

Sign up to answer this question »