3 mai 2024
MacOS Environment with Yabai and SketchyBar
4 minutes de lecture
After several years on Linux, I recently decided to return to a MacOS work environment. So, I sought to reconfigure my workspace to find methods similar to the Regolith environment that I particularly appreciate.
It's a pleasure to return to the reliability and quality of Apple hardware, but the very mouse-oriented navigation or the pad's "gestures" do not suit me. I want to find:
- a "tiling" type window manager to maximize the workspace
- fast and simple navigation primarily on the keyboard
- a high-performance and customizable terminal
- workspaces to organize applications
Note: I am not a purist of keyboard navigation, I use the mouse for many tasks, especially window focus and machine gun fire on aliens.
Window Manager (~10 mins)
Fortunately, there are already very advanced alternatives. I chose yabai which seems the most advanced and offers configuration via CLI. Amethyst is an alternative that offers a graphical interface but does not allow control of "Spaces" or modify the native properties of windows.
To install Yabai there are a few steps to follow
- installation of the binary
- service start
- injection script configuration
- SIP (System Integrity Protection) disabling
Everything is detailed in the Github wiki.
Regarding the configuration, I stayed very close to the default one :
#!/usr/bin/env sh
yabai -m signal --add event=dock_did_restart action="sudo yabai --load-sa"
sudo yabai --load-sa
# global settings
yabai -m config \
external_bar all:40:0 \
menubar_opacity 1.0 \
mouse_follows_focus off \
focus_follows_mouse off \
window_origin_display default \
window_placement second_child \
window_zoom_persist on \
window_shadow on \
window_animation_duration 0.0 \
window_opacity_duration 0.0 \
active_window_opacity 1.0 \
normal_window_opacity 0.90 \
window_opacity off \
insert_feedback_color 0xffd75f5f \
split_ratio 0.50 \
split_type auto \
auto_balance off \
top_padding 8 \
bottom_padding 8 \
left_padding 8 \
right_padding 8 \
window_gap 04 \
layout bsp \
mouse_modifier fn \
mouse_action1 move \
mouse_action2 resize \
mouse_drop_action swap
echo "yabai configuration loaded."
Keyboard Navigation (~10 mins)
For keyboard navigation, I use skhd, a simple keyboard shortcut handler, which can easily be associated with yabai
commands.
The installation is very fast and requires little configuration :
brew install koekeishiya/formulae/skhd
skhd --start-service
And here's an example of a configuration file:
# fast focus spaces
lalt - 0x12 : yabai -m space --focus 1
lalt - 0x14 : yabai -m space --focus 3
lalt - 0x13 : yabai -m space --focus 2
lalt - 0x15 : yabai -m space --focus 4
# send window to desktop
shift + ctrl - 0x12 : yabai -m window --space 1;
shift + ctrl - 0x13 : yabai -m window --space 2;
shift + ctrl - 0x14 : yabai -m window --space 3;
shift + ctrl - 0x15 : yabai -m window --space 4;
shift + ctrl - 0x17 : yabai -m window --space 5;
shift + ctrl - 0x16 : yabai -m window --space 6;
# toggle window zoom
alt - f : yabai -m window --toggle zoom-fullscreen
I encountered some difficulties with the French keyboard and finding the right key names, but the Key Codes software helped me a lot.
It's possible to go much further with the configuration. For my return from Linux, I stuck with simple shortcuts for now that do not conflict with native shortcuts (my first braces were a bit tedious...).
Menu Bar and Workspaces (~10 mins to ♾️)
Last step which is not really necessary but which I found quite cool: the menu bar. Beware, here is where Pandora's box really opens, as evidenced by these numerous customization examples.
SketchyBar is also easily installed with brew :
brew tap FelixKratz/formulae
brew install sketchybar
For the configuration, I was heavily inspired by developer Felix Kratz's setup with:
- active workspaces and applications
- battery indicator
- volume
- date and time
- Slack notifications
The only configuration I added is that of Slack with the following script:
#!/bin/bash
SLACK_INFO=$(lsappinfo info -only StatusLabel `lsappinfo find LSDisplayName=Slack`)
COUNT=${SLACK_INFO:25:1}
if [ $COUNT = "•" ]; then
DRAWING=off
else
DRAWING=on
fi
sketchybar --set slack drawing=$DRAWING label="Slack (${COUNT})"
and its definition in the configuration:
slack=(
update_freq=3
updates=on
icon.drawing=off
label.font="$FONT:Bold:14.0"
script="$PLUGIN_DIR/slack.sh"
)
sketchybar --add item slack right \
--set slack "${slack[@]}" \
Conclusion
I am very satisfied with my current work environment. Some MacOS applications may prove recalcitrant, like "System settings" in terms of tiling, but these are really marginal cases. I have found an efficient work methodology and fast navigation.
In the end, the only annoying points are old habits or environment changes on the same day between MacOS, Linux and Windows (home computer).
I had a project to make a small animation with a black cat 🐈⬛ running on the menu bar each time I do a git push
but it's clearly at the bottom of the priority list.
I hope you will have as much fun as I did configuring your environment, don't hesitate to share your tips and configurations!