Skip to content
Snippets Groups Projects

Karabiner

Merged Dusan Orlovic requested to merge karabiner into main
7 files
+ 118
92
Compare changes
  • Side-by-side
  • Inline
Files
7
+ 93
38
# Keyboard shortcuts to switch windows on macos
Use keyboard shortcut to jump to specific terminal window.
First install Karabiner and play with keyboard. You can switch between
applications with a keyboard shortcuts.
Probably that is enough for most users.
For those users who want to switch to specific window of the same application we
need to use Scripts to find that window and activate it.
## Install Karabiner-elements
Former name for this app was KeyRemap4MacBook.
Former name for Karabiner app was KeyRemap4MacBook.
Download pkg and allow permission like
https://karabiner-elements.pqrs.org/docs/getting-started/installation/
The best is to use git to track changes but since karabiner will override the
file we can not use soft links. We will copy whole file
The best is to use git to track configuration changes here in repo and since we
can not use soft links (since karabiner will override the file, not the content,
so the soft link is removed) we will copy whole file
```
cp ~/.config/karabiner/karabiner.json ~/trk.tools/sh/keyboard-shortcuts-to-switch-windows-on-macos/karabiner.json
```
Use `Karabiner-eventviewer` to find key codes
and when you update konfig in source, you can push the changes back to karabiner
```
# be careful since you will override existing karabiner configuration
cp ~/trk.tools/sh/keyboard-shortcuts-to-switch-windows-on-macos/karabiner.json ~/.config/karabiner/karabiner.json
```
Use `Karabiner-eventviewer` to find key codes.
## Plugins
## Complex modifications
https://ke-complex-modifications.pqrs.org/
You can find this site in Karabiner -> Complex rules -> Add predefined rule ->
Import more rules from the internet
Very usefull mappings:
* exchange semicolon and colon
https://ke-complex-modifications.pqrs.org/#exchange_semicolon_and_colon
* Exchange numbers and symbols (1234567890 and !@#$%^&*())
https://ke-complex-modifications.pqrs.org/#exchange_numbers_and_symbols
* Exchange single and double quote
https://ke-complex-modifications.pqrs.org/#exchange_single_and_double_quote
* capslock + hjkl to arrow keys
only CAPSLOCK + hjkl to arrow keys (Post CAPSLOCK if press CAPSLOCK alone)
https://ke-complex-modifications.pqrs.org/#caps_lock_toolbox
* custom rule similar to single and double quote, I created for pipe and
backslash
https://ke-complex-modifications.pqrs.org/#exchange_vertical_bar_pipe_and_backslash
* command open bracket to page down
https://ke-complex-modifications.pqrs.org/#fn_open_bracket_to_page_up
* exchange [] and {} https://ke-complex-modifications.pqrs.org/#exchange_square_brackets_and_curly_brackets
* Change left_command+b/f to alt+b/f (also need to enable in Termial ->
Preferences -> Profiles -> Keyboard -> Use Option as Meta key)
Probably not needed
* exchange [] and {} https://ke-complex-modifications.pqrs.org/#exchange_square_brackets_and_curly_brackets
* Remap section sign (§) from British Keyboard to US's backtick + plus minus (±)
to tilde (~) https://ke-complex-modifications.pqrs.org/#section_sign_to_backtick
* Left ctrl + hjkl to arrow keys Vim
https://ke-complex-modifications.pqrs.org/#ctrl_plus_hjkl_to_arrow_keys
but I change to capslock
* Caps Lock Vim Movements (rev 2)
https://ke-complex-modifications.pqrs.org/#capslock_vim_movements
Add mapings to activate specific apps, for example:
* `left_command + u` Google Chrome
* `left_command + i` Brawe Browser
* `left_command + o` ChatGPT
* `left_command + p` Safari
using simple config
```
{
"description": "left_command + u to activate Google",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "u",
"modifiers": {
"mandatory": ["left_command"]
}
},
"to": [
{
"shell_command": "open -a 'Google Chrome'"
}
]
}
]
}
```
If you need to jump to specific window inside the same app than follow next
section
## Keyboard shortcut to switch windows
## Activate specific window
Download this repo at specific location
```
mkdir -p ~/trk.tools/sh
cd ~/trk.tools/sh
git clone https://trk.tools/sh/keyboard-shortcuts-to-switch-windows-on-macos.git
cd keyboard-shortcuts-to-switch-windows-on-macos
```
We use two Scripts files `bind_front_window_to_key.scpt` and
`activate_window.scpt` and store data windowId and windowName inside
`~/trk.tools/sh/keyboard-shortcuts-to-switch-windows-on-macos/data.plist` file.
If you cloned in different folder than update both scpt scripts.
We use helper function to bind new key, so we need to load with:
We use helper function `b` to bind key, so lets add to bashrc (or zhrc)
```
. b.sh
source b.sh
# or if you want to be available in any shell, you can add to bashrc
echo >> ~/.bashrc
echo "# https://trk.tools/sh/keyboard-shortcuts-to-switch-windows-on-macos" >> ~/.bashrc
echo . `pwd`/b.sh >> ~/.bashrc
echo source `pwd`/b.sh >> ~/.bashrc
```
Open new terminal and bind specific window
```
b
# press key, for example "k"
```
We can bind specific window
To activate window you can open another terminal and run
```
b k
cd ~/trk.tools/sh/keyboard-shortcuts-to-switch-windows-on-macos
osascript ./activate_window.scpt k
```
or script to load all windows. This will change on your local system (for your
screen dimension and your default programs)
and you should be active in first `k` window.
You can create a script to load multiple windows and bind to different keys.
Let's create local bin folder (if not already exists) and link two files.
```
mkdir -p ~/.local/bin
ln -s $(pwd)/all.sh ~/.local/bin
ln -s $(pwd)/start_screen.sh ~/.local/bin
ln -s $(pwd)/start_gnu_screen_for_key_and_left_top_right_bottom.sh ~/.local/bin
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
```
so you can local all windows in terminal with
You should update those two files `all.sh` and
`start_gnu_screen_for_key_and_left_top_right_bottom.sh` to match your screen
dimension and your default programs.
So now after you restart mac, you can simply stary all your default terminal
windows with one command
```
all.sh
```
You can ignore those changes in keys, geometry and default apps
```
git update-index --no-assume-unchanged data.plist all.sh start_screen.sh
git update-index --assume-unchanged data.plist all.sh start_gnu_screen_for_key_and_left_top_right_bottom.sh
```
We call scpt file from shell using osascript but we need to enable Privacy ->
Accessibility to Terminal
otherwise we get an error:
> /Users/dule/config/bashrc/mac_scripts/mac_run_command_in_slash_window.scpt: execution error: System Events got an error: osascript is not allowed to send keystrokes. (1002)
https://stackoverflow.com/a/71826193/287166
“karabiner_console_user_server“ wants access to control “Terminal“. Allowing
control will provide access to documents and data in “Terminal“, and to perform
actions within that app.
Loading