MacOS - skhd hotkey
Problems
Every time I wish to switch between windows, I must use ⌘ + tab
, which is rather inconvenient.
Similarly, to open a new iTerm, I have to use ⌘ + space
to access Alfred, then type “iTerm” to launch it. This process is equally cumbersome.
Solution
skhd is a simple hotkey daemon for macOS. We can use it to define hotkeys to switch between windows, open terminal, etc.
Install
brew install koekeishiya/formulae/skhd
skhd --start-service
Configuration
Create a file ~/.skhdrc
and add the following content:
# Opens app
# Switch to or open app
lctrl + shift - h : osascript "${HOME}"/.config/yabai/scripts/toggle_app.scpt "Google Chrome"
lctrl + shift - j : osascript "${HOME}"/.config/yabai/scripts/toggle_app.scpt "Slack"
lctrl + shift - k : osascript "${HOME}"/.config/yabai/scripts/toggle_app.scpt "iTerm"
lctrl + shift - l : osascript "${HOME}"/.config/yabai/scripts/toggle_app.scpt "Obsidian"
lctrl + shift - m : osascript "${HOME}"/.config/yabai/scripts/toggle_app.scpt "Messenger"
# toggle app.scpt
on run argv
set appName to item 1 of argv
if application appName is running then
tell application appName
activate
end tell
else
tell application appName
launch
activate
end tell
end if
end run
Now, we can use lctrl + shift - h
to switch to or open Google Chrome, lctrl + shift - j
to switch to or open Slack, etc.
Or you can config other hotkeys as you want. eg: alt - g
to open Google Chrome, alt - s
to open Slack, etc.
You can read more configuration in my ~/.skhdrc