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.
Post History
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: #!/...
#5: Post edited
- Another approach is to use [Karabiner-Elements](https://github.com/pqrs-org/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](https://github.com/davidpurnell/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
- this answer assumes that you have 3 spaces. Adjust the numbers in `PrevSpace = 3` and `NextSpace == 4` to match your number of spaces(+1)- - 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
- Another approach is to use [Karabiner-Elements](https://github.com/pqrs-org/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](https://github.com/davidpurnell/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
#4: Post edited
- Another approach is to use [Karabiner-Elements](https://github.com/pqrs-org/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](https://github.com/davidpurnell/SpaceInfo)
- `Space_prev`:
- ```
- #!/bin/zsh
export CurrentSpace=$(SpaceInfo --active-space); export NextSpace=$(($CurrentSpace-1)); if [[ $NextSpace = 0 ]] then; export NextSpace=3; 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=$(SpaceInfo --active-space); export NextSpace=$(($CurrentSpace+1)); if [[ $NextSpace = 4 ]] 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
- - this answer assumes that you have 3 spaces. Adjust the numbers in `PrevSpace = 3` and `NextSpace == 4` to match your number of spaces(+1)
- - 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
- Another approach is to use [Karabiner-Elements](https://github.com/pqrs-org/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](https://github.com/davidpurnell/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
- - this answer assumes that you have 3 spaces. Adjust the numbers in `PrevSpace = 3` and `NextSpace == 4` to match your number of spaces(+1)
- - 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
#3: Post edited
- Another approach is to use [Karabiner-Elements](https://github.com/pqrs-org/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](https://github.com/davidpurnell/SpaceInfo)
- `Space_prev`:
- ```
- #!/bin/zsh
- export CurrentSpace=$(SpaceInfo --active-space); export NextSpace=$(($CurrentSpace-1)); if [[ $NextSpace = 0 ]] then; export NextSpace=3; 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=$(SpaceInfo --active-space); export NextSpace=$(($CurrentSpace+1)); if [[ $NextSpace = 4 ]] 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"
- }
- ]
- }
- ```
(this answer assumes that `cmd+number` is the shortcut to go to the space of a specific number)
- Another approach is to use [Karabiner-Elements](https://github.com/pqrs-org/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](https://github.com/davidpurnell/SpaceInfo)
- `Space_prev`:
- ```
- #!/bin/zsh
- export CurrentSpace=$(SpaceInfo --active-space); export NextSpace=$(($CurrentSpace-1)); if [[ $NextSpace = 0 ]] then; export NextSpace=3; 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=$(SpaceInfo --active-space); export NextSpace=$(($CurrentSpace+1)); if [[ $NextSpace = 4 ]] 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
- - this answer assumes that you have 3 spaces. Adjust the numbers in `PrevSpace = 3` and `NextSpace == 4` to match your number of spaces(+1)
- - 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
#2: Post edited
- Another approach is to use [Karabiner-Elements](https://github.com/pqrs-org/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](https://github.com/davidpurnell/SpaceInfo)
- `Space_prev`:
- ```
- #!/bin/zsh
- export CurrentSpace=$(SpaceInfo --active-space); export NextSpace=$(($CurrentSpace-1)); if [[ $NextSpace = 0 ]] then; export NextSpace=3; 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=$(SpaceInfo --active-space); export NextSpace=$(($CurrentSpace+1)); if [[ $NextSpace = 4 ]] 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"
- }
- ]
- }
```
- Another approach is to use [Karabiner-Elements](https://github.com/pqrs-org/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](https://github.com/davidpurnell/SpaceInfo)
- `Space_prev`:
- ```
- #!/bin/zsh
- export CurrentSpace=$(SpaceInfo --active-space); export NextSpace=$(($CurrentSpace-1)); if [[ $NextSpace = 0 ]] then; export NextSpace=3; 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=$(SpaceInfo --active-space); export NextSpace=$(($CurrentSpace+1)); if [[ $NextSpace = 4 ]] 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"
- }
- ]
- }
- ```
- (this answer assumes that `cmd+number` is the shortcut to go to the space of a specific number)
#1: Initial revision
Another approach is to use [Karabiner-Elements](https://github.com/pqrs-org/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](https://github.com/davidpurnell/SpaceInfo)
`Space_prev`:
```
#!/bin/zsh
export CurrentSpace=$(SpaceInfo --active-space); export NextSpace=$(($CurrentSpace-1)); if [[ $NextSpace = 0 ]] then; export NextSpace=3; 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=$(SpaceInfo --active-space); export NextSpace=$(($CurrentSpace+1)); if [[ $NextSpace = 4 ]] 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"
}
]
}
```
