Skip to content

Instantly share code, notes, and snippets.

@dskindell
Last active January 23, 2024 18:46
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dskindell/374b2a3d8fd9bc4ebc33be4a4486b31e to your computer and use it in GitHub Desktop.
Save dskindell/374b2a3d8fd9bc4ebc33be4a4486b31e to your computer and use it in GitHub Desktop.
OSX yabai & skhd Configuration
####### Shortcut Hotkeys #############
# open terminal
lalt - return : $HOME/.config/skhd/open_terminal.sh --single-instance
lalt + shift - return : $HOME/.config/skhd/open_terminal.sh
#alt - t : osascript -e 'tell application "iTerm2" to create window with default profile'
# restart Yabi, SpaceBar, and SKHD
#lalt + lcmd - r : \
# launchctl kickstart -k "gui/${UID}/homebrew.mxcl.yabai"; \
# skhd --reload
lalt + lcmd - r : launchctl kickstart -k "gui/${UID}/homebrew.mxcl.yabai"; \
osascript -e 'tell application id "tracesOf.Uebersicht" to refresh widget id "simple-bar-spaces-jsx"'; \
skhd --reload;
####### Application Blacklists #############
# {
#.blacklist [
# "IntelliJ IDEA"
#]
# }
####### Monitor Management Hotkeys #############
# {
# focus monitor
alt + ctrl - x : yabai -m display --focus recent
alt + ctrl - z : yabai -m display --focus prev
alt + ctrl - c : yabai -m display --focus next
alt + ctrl - 1 : yabai -m display --focus 1
alt + ctrl - 2 : yabai -m display --focus 2
alt + ctrl - 3 : yabai -m display --focus 3
# }
####### Workspace Management Hotkeys #############
# {
# navigate to specific workspace (with back and forth support)
# # Note: script fails when workspace is empty due to Yabai not reporting the workspace (bug?)
# # best to use the create + move window command instead of creating a blank window
alt - 1 : $HOME/.config/skhd/switch_workspace.sh 1
alt - 2 : $HOME/.config/skhd/switch_workspace.sh 2
alt - 3 : $HOME/.config/skhd/switch_workspace.sh 3
alt - 4 : $HOME/.config/skhd/switch_workspace.sh 4
alt - 5 : $HOME/.config/skhd/switch_workspace.sh 5
alt - 6 : $HOME/.config/skhd/switch_workspace.sh 6
alt - 7 : $HOME/.config/skhd/switch_workspace.sh 7
alt - 8 : $HOME/.config/skhd/switch_workspace.sh 8
alt - 9 : $HOME/.config/skhd/switch_workspace.sh 9
#alt - 0 : $HOME/.config/skhd/switch_workspace.sh 10
# navigate workspaces next / previous
cmd - h : yabai -m space --focus prev
cmd - l : yabai -m space --focus next
# navigate workspaces next / previous using arrow keys
#cmd - left : yabai -m space --focus prev
#cmd - right : yabai -m space --focus next
# change layout of desktop
alt - e : yabai -m space --layout bsp
alt - s : yabai -m space --layout float
# destroy desktop
alt + cmd - w : yabai -m space --destroy
# create desktop and follow focus
# Note: script fails when workspace is empty due to Yabai not reporting the workspace (bug?)
# best to use the create + move window command instead of creating a blank window
alt - n : yabai -m space --create;\
index="$(yabai -m query --spaces --display | jq 'map(select(."native-fullscreen" == 0))[-1].index')"; \
yabai -m space --focus "${index}"
# }
####### Window Management Hotkeys #############
# {
#### Navigate Windows ######
# {
# change focus
alt - h : yabai -m window --focus west
alt - j : yabai -m window --focus south
alt - k : yabai -m window --focus north
alt - l : yabai -m window --focus east
# (alt) change focus (using arrow keys)
alt - left : yabai -m window --focus west
alt - down : yabai -m window --focus south
alt - up : yabai -m window --focus north
alt - right : yabai -m window --focus east
# go back to previous workspace (kind of like back_and_forth in i3)
alt - b : yabai -m space --focus recent
# }
#### Configure New Window ######
# {
# set insertion point in focused container
alt + ctrl - h : yabai -m window --insert west
alt + ctrl - j : yabai -m window --insert south
alt + ctrl - k : yabai -m window --insert north
alt + ctrl - l : yabai -m window --insert east
# (alt) set insertion point in focused container using arrows
alt + ctrl - left : yabai -m window --insert west
alt + ctrl - down : yabai -m window --insert south
alt + ctrl - up : yabai -m window --insert north
alt + ctrl - right : yabai -m window --insert east
# }
#### Move Windows in Workspace ######
# {
# shift window in current workspace
alt + shift - h : yabai -m window --warp west
alt + shift - j : yabai -m window --warp south
alt + shift - k : yabai -m window --warp north
alt + shift - l : yabai -m window --warp east
# alternatively, use the arrow keys
alt + shift - left : yabai -m window --warp west
alt + shift - down : yabai -m window --warp south
alt + shift - up : yabai -m window --warp north
alt + shift - right : yabai -m window --warp east
# Rotate windows
alt - r : yabai -m space --rotate 270
#alt + ctrl - r : yabai -m space --rotate 90
# # mirror tree y-axis
alt + shift - y : yabai -m space --mirror y-axis
# # mirror tree x-axis
alt + shift - x : yabai -m space --mirror x-axis
# }
#### Resice Windows ######
# {
# increase window size
alt + shift - a : yabai -m window --resize left:-60:0
alt + shift - s : yabai -m window --resize bottom:0:60
alt + shift - w : yabai -m window --resize top:0:-60
alt + shift - d : yabai -m window --resize right:60:0
# decrease window size
cmd + shift - a : yabai -m window --resize left:60:0
cmd + shift - s : yabai -m window --resize bottom:0:-60
cmd + shift - w : yabai -m window --resize top:0:60
cmd + shift - d : yabai -m window --resize right:-60:0
# balance size of windows
alt + shift - 0 : yabai -m space --balance
# enter fullscreen mode for the focused container
alt - f : yabai -m window --toggle zoom-fullscreen
# toggle window native fullscreen
alt + shift - f : yabai -m window --toggle native-fullscreen
# }
#### Move Windows to Workspace ######
# {
# Move focused window to specific workspace (with back and forth support)
alt + shift - 1 : $HOME/.config/skhd/move_to_workspace.sh 1
alt + shift - 2 : $HOME/.config/skhd/move_to_workspace.sh 2
alt + shift - 3 : $HOME/.config/skhd/move_to_workspace.sh 3
alt + shift - 4 : $HOME/.config/skhd/move_to_workspace.sh 4
alt + shift - 5 : $HOME/.config/skhd/move_to_workspace.sh 5
alt + shift - 6 : $HOME/.config/skhd/move_to_workspace.sh 6
alt + shift - 7 : $HOME/.config/skhd/move_to_workspace.sh 7
alt + shift - 8 : $HOME/.config/skhd/move_to_workspace.sh 8
alt + shift - 9 : $HOME/.config/skhd/move_to_workspace.sh 9
#alt + shift - 0 : $HOME/.config/skhd/move_to_workspace.sh 10
# move focused window to previous workspace
alt + shift - b : yabai -m window --space recent; \
yabai -m space --focus recent
# move focused window to next/prev workspace
#cmd + shift - h : yabai -m window --space prev
#cmd + shift - l : yabai -m window --space next
# move focused window to next/prev workspace using arrow keys
#cmd + shift - left : yabai -m window --space prev
#cmd + shift - right : yabai -m window --space next
# create desktop, move window and follow focus
alt + shift - n : yabai -m space --create;\
index="$(yabai -m query --spaces --display | jq 'map(select(."native-fullscreen" == 0))[-1].index')"; \
yabai -m window --space "${index}";\
yabai -m space --focus "${index}"
# create desktop, move window and stay in current workspace
alt + shift + cmd - n : yabai -m space --create;\
index="$(yabai -m query --spaces --display | jq 'map(select(."native-fullscreen" == 0))[-1].index')"; \
yabai -m window --space "${index}"
# }
#### Float Windows ######
# {
# float / unfloat window and center on screen
#alt - c : yabai -m window --toggle float;\
# yabai -m window --grid 4:4:1:1:2:2
# float / unfloat window and leave in its current location
alt + shift - space : yabai -m window --toggle float
#alt + ctrl - space : yabai -m window --toggle float
# toggle sticky
alt + shift - g : yabai -m window --toggle sticky
# make floating window fill screen
#alt + cmd - up : yabai -m window --grid 1:1:0:0:1:1
# make floating window fill left-half of screen
#alt + cmd - left : yabai -m window --grid 1:2:0:0:1:1
# make floating window fill right-half of screen
#alt + cmd - right : yabai -m window --grid 1:2:1:0:1:1
# }
# }
#!/usr/bin/env bash
# Yabai workspace switcher with back and forth support
if [[ $# -eq 0 ]]; then
yabai -m window --space recent
yabai -m space --focus recent
else
current_ws=$(yabai -m query --spaces --display | jq 'map(select(."focused" == 1))[0].index')
if [[ "$current_ws" == $1 ]]; then
# go to previous workspace
yabai -m window --space recent
yabai -m space --focus recent
else
# else, go to the workspace specified
yabai -m window --space $1
yabai -m space --focus $1
fi
fi
#!/usr/bin/env bash
# opens a terminal window on the correct display, triggered by hotkeys from SKHD
# Terminal opens on primary display, nothing special if already on it
display=$(yabai -m query --displays --display | jq ".index")
if [[ ${display:-100} -eq 1 ]]; then
# Just open the terminal if on the primary (first) display
# /Applications/kitty.app/Contents/MacOS/kitty --single-instance -d ~
/Applications/iTerm.app/Contents/MacOS/iTerm2 --single-instance -d ~
else
# otherwise, track the current space to open the window and move it to the focused space
# after it starts up on the primary display
space=$(yabai -m query --spaces --display | jq 'map(select(."focused" == 1))[0].index')
#/Applications/kitty.app/Contents/MacOS/kitty --single-instance -d ~
/Applications/iTerm.app/Contents/MacOS/iTerm2 --single-instance -d ~
sleep 1
yabai -m window --space "${space}"
yabai -m space --focus "${space}"
fi
#!/usr/bin/env bash
# Yabai workspace switcher with back and forth support
if [[ $# -eq 0 ]]; then
yabai -m space --focus recent
else
current_ws=$(yabai -m query --spaces --display | jq 'map(select(."focused" == 1))[0].index')
if [[ "$current_ws" == $1 ]]; then
# go to previous workspace
yabai -m space --focus recent
else
# else, go to the workspace specified
yabai -m space --focus $1
fi
fi
#!/usr/bin/env sh
# the scripting-addition must be loaded manually if
# you are running yabai on macOS Big Sur. Uncomment
# the following line to have the injection performed
# when the config is executed during startup.
#
# for this to work you must configure sudo such that
# it will be able to run the command without password
#
# see this wiki page for information:
# - https://github.com/koekeishiya/yabai/wiki/Installing-yabai-(latest-release)
#
sudo yabai --install-sa
sudo yabai --load-sa
yabai -m signal --add event=dock_did_restart action="sudo yabai --load-sa"
# bar settings
#
# pad top of display to support simple-bar
# bar settings hack to get different paddings per display
yabai -m config external_bar main:12:0
# yabai -m config external_bar all:28:0
#yabai -m config top_padding 28
yabai -m config external_bar all:28:0
# global settings
yabai -m config mouse_follows_focus off
yabai -m config focus_follows_mouse autofocus
yabai -m config window_placement second_child
yabai -m config window_topmost off
yabai -m config window_opacity off
#yabai -m config window_opacity_duration 0.0
yabai -m config window_shadow on
yabai -m config active_window_opacity 1.0
yabai -m config normal_window_opacity 0.90
yabai -m config split_ratio 0.50
yabai -m config auto_balance off
# Mouse support
yabai -m config mouse_modifier ctrl
yabai -m config mouse_action1 move
yabai -m config mouse_action2 resize
# general space settings
yabai -m config layout bsp
yabai -m config bottom_padding 0
yabai -m config left_padding 0
yabai -m config right_padding 0
yabai -m config window_gap 0
# float system preferences
yabai -m rule --add app='^System Information$' manage=off
yabai -m rule --add app='^System Preferences$' manage=off
yabai -m rule --add title='Preferences$' manage=off
yabai -m rule --add app='Finder' title='Info$' manage=off
# float Better Touch Tool Preference window
yabai -m rule --add title='^BetterTouchTool' manage=off
# float settings windows
yabai -m rule --add title='Settings$' manage=off
# float Cisco AnyConnect
yabai -m rule --add app='^Cisco AnyConnect Secure Mobility Client$' manage=off
# float IntelliJ Preference panes
yabai -m rule --add app='IntelliJ IDEA' title='^$' manage=off
yabai -m rule --add app='IntelliJ IDEA' title='Project Structure' manage=off
yabai -m rule --add app='IntelliJ IDEA' title='Preferences' manage=off
yabai -m rule --add app='IntelliJ IDEA' title='Edit configuration' manage=off
yabai -m rule --add app='IntelliJ IDEA' title='Select Classes to Import' manage=off
yabai -m rule --add app='IntelliJ IDEA' title='Licenses' manage=off
yabai -m rule --add app='WebStorm' title='^$' manage=off
yabai -m rule --add app='WebStorm' title='Project Structure' manage=off
yabai -m rule --add app='WebStorm' title='Preferences' manage=off
yabai -m rule --add app='WebStorm' title='Edit configuration' manage=off
yabai -m rule --add app='WebStorm' title='Configurations$' manage=off
# float Cisco AnyConnect
yabai -m rule --add app='^Cisco AnyConnect Secure Mobility Client$' manage=off
# Note: IDEA opens in floating mode due to "title='^$" match, need to add support for matching on "subrole==AXDialog" vs "AXSystemDialog".
#yabai -m rule --add app='IntelliJ IDEA' title!='^$' manage=on
# float Jetbrains Toolbox
yabai -m rule --add app='JetBrains Toolbox' manage=off
# update battery loop from wiki
# https://github.com/koekeishiya/yabai/wiki/Tips-and-tricks#updating-battery-icon-in-status-bar-based-on-battery-level
function update_battery_loop() {
while true; do
# Get the current battery percentage.
battery=$(pmset -g batt | grep -Eo "\d+%" | cut -d% -f1)
if [ $battery -gt 84 ]; then
spacebar -m config status_bar_power_icon_strip  
elif [ $battery -gt 60 ]; then
spacebar -m config status_bar_power_icon_strip  
elif [ $battery -gt 39 ]; then
spacebar -m config status_bar_power_icon_strip  
elif [ $battery -gt 14 ]; then
spacebar -m config status_bar_power_icon_strip  
else
spacebar -m config status_bar_power_icon_strip  
fi
# wait 5 seconds
sleep 5
done
}
# run the function async
# update_battery_loop &
# Refresh Uebersicht status bar (disabled due to latency issues and trouble getting active window title)
# yabai -m signal --add event=space_changed \
# action="osascript -e 'tell application \"Übersicht\" to refresh widget id \"nibar-spaces-primary-jsx\"'"
# yabai -m signal --add event=display_changed \
# action="osascript -e 'tell application \"Übersicht\" to refresh widget id \"nibar-spaces-primary-jsx\"'"
# yabai -m signal --add event=space_changed \
# action="osascript -e 'tell application \"Übersicht\" to refresh widget id \"nibar-spaces-secondary-jsx\"'"
# yabai -m signal --add event=display_changed \
# action="osascript -e 'tell application \"Übersicht\" to refresh widget id \"nibar-spaces-secondary-jsx\"'"
echo "yabai configuration loaded.."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment