### Start Yabai Service Source: https://github.com/koekeishiya/yabai/wiki/Installing-yabai-(latest-release) Starts the yabai service. This command may prompt the user to grant accessibility permissions to yabai in System Settings. ```shell # start yabai yabai --start-service ``` -------------------------------- ### Install Yabai Binary using Installer Script Source: https://github.com/koekeishiya/yabai/wiki/Installing-yabai-(latest-release) Installs the yabai binary and man page using a curl-piped script. It can install to default locations or custom directories like ~/.local/bin. ```shell # install yabai binary into /usr/local/bin and man page yabai.1 into /usr/local/man/man1 curl -L https://raw.githubusercontent.com/asmvik/yabai/master/scripts/install.sh | sh /dev/stdin # install yabai binary into ~/.local/bin and man page yabai.1 into ~/.local/man curl -L https://raw.githubusercontent.com/asmvik/yabai/master/scripts/install.sh | sh /dev/stdin ~/.local/bin ~/.local/man ``` -------------------------------- ### Add Scripting Addition Loading to Yabairc Source: https://github.com/koekeishiya/yabai/wiki/Installing-yabai-(latest-release) Shows how to add the command to load the yabai scripting addition to the `yabairc` configuration file. This ensures the scripting addition is loaded automatically when yabai starts, provided the sudoers configuration is correct. ```shell # for this to work you must configure sudo such that # it will be able to run the command without password yabai -m signal --add event=dock_did_restart action="sudo yabai --load-sa" sudo yabai --load-sa # .. more yabai startup stuff ``` -------------------------------- ### Install Yabai using Homebrew Source: https://github.com/koekeishiya/yabai/wiki/Installing-yabai-(latest-release) Installs yabai using the asmvik/formulae tap from Homebrew. This is an alternative installation method. ```shell brew install asmvik/formulae/yabai ``` -------------------------------- ### Window Cycling Script Example Source: https://context7.com/koekeishiya/yabai/llms.txt A bash script demonstrating how to cycle through windows, swapping their positions. It uses `yabai` and `jq` to query window IDs and repeatedly swap windows until an error occurs. ```shell # Window cycling script example #!/bin/bash win=$(yabai -m query --windows --window last | jq '.id') while : ; do yabai -m window $win --swap prev &> /dev/null if [[ $? -eq 1 ]]; then break fi done ``` -------------------------------- ### Configure Sudoers for Yabai Scripting Addition Source: https://github.com/koekeishiya/yabai/wiki/Installing-yabai-(latest-release) Demonstrates how to configure the sudoers file to allow the user to execute `yabai --load-sa` as root without a password. This involves creating a new file in `/private/etc/sudoers.d/` and specifying the path to the yabai binary and its SHA256 hash. ```shell # create a new file for writing - visudo uses the vim editor by default. # go read about this if you have no idea what is going on. sudo visudo -f /private/etc/sudoers.d/yabai # input the line below into the file you are editing. # replace with the path to the yabai binary (output of: which yabai). # replace with your username (output of: whoami). # replace with the sha256 hash of the yabai binary (output of: shasum -a 256 $(which yabai)). # this hash must be updated manually after upgrading yabai. ALL=(root) NOPASSWD: sha256: --load-sa ``` ```shell echo "$(whoami) ALL=(root) NOPASSWD: sha256:$(shasum -a 256 $(which yabai) | cut -d " " -f 1) $(which yabai) --load-sa" | sudo tee /private/etc/sudoers.d/yabai ``` -------------------------------- ### Update Yabai and Reconfigure Scripting Addition Source: https://github.com/koekeishiya/yabai/wiki/Installing-yabai-(latest-release) Provides commands to stop the current yabai service, upgrade yabai using either the installer script or Homebrew, and then restart the service. Reconfiguring the scripting addition is also mentioned as a necessary step after upgrading. ```shell # stop yabai yabai --stop-service # upgrade yabai with installer script -- (with or without directory override) curl -L https://raw.githubusercontent.com/asmvik/yabai/master/scripts/install.sh | sh /dev/stdin # or # upgrade yabai with homebrew (remove old service file because homebrew changes binary path) yabai --uninstall-service brew upgrade yabai # start yabai yabai --start-service ``` -------------------------------- ### Install Yabai from HEAD using Homebrew Source: https://github.com/koekeishiya/yabai/wiki/Installing-yabai-(from-HEAD) Installs the latest development version of Yabai using Homebrew. Requires uninstalling any existing release version first. The installation is followed by codesigning the binary with a self-signed certificate. ```shell brew uninstall asmvik/formulae/yabai brew install asmvik/formulae/yabai --HEAD codesign -fs 'yabai-cert' $(brew --prefix yabai)/bin/yabai ``` -------------------------------- ### skhd Integration for Yabai Window Management Source: https://context7.com/koekeishiya/yabai/llms.txt Provides example skhd configuration for controlling yabai window management actions using keyboard shortcuts. Includes commands for focusing, swapping, warping windows, managing spaces, toggling window states, and resizing. ```shell # ~/.config/skhd/skhdrc # Focus windows with vim-style keys 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 # Swap windows shift + alt - h : yabai -m window --swap west shift + alt - j : yabai -m window --swap south shift + alt - k : yabai -m window --swap north shift + alt - l : yabai -m window --swap east # Move/warp windows shift + cmd - h : yabai -m window --warp west shift + cmd - j : yabai -m window --warp south shift + cmd - k : yabai -m window --warp north shift + cmd - l : yabai -m window --warp east # Focus spaces alt - 1 : yabai -m space --focus 1 alt - 2 : yabai -m space --focus 2 alt - 3 : yabai -m space --focus 3 # Send window to space shift + alt - 1 : yabai -m window --space 1 shift + alt - 2 : yabai -m window --space 2 # Toggle window states alt - f : yabai -m window --toggle zoom-fullscreen alt - t : yabai -m window --toggle float --grid 4:4:1:1:2:2 alt - s : yabai -m window --toggle sticky # Resize windows ctrl + alt - h : yabai -m window --resize left:-50:0 ctrl + alt - l : yabai -m window --resize right:50:0 ctrl + alt - j : yabai -m window --resize bottom:0:50 ctrl + alt - k : yabai -m window --resize top:0:-50 # Balance and rotate shift + alt - 0 : yabai -m space --balance alt - r : yabai -m space --rotate 90 ``` -------------------------------- ### Manage yabai Service Source: https://context7.com/koekeishiya/yabai/llms.txt Commands to manage yabai as a launchd service. This includes installing, starting, stopping, restarting, and uninstalling the service, as well as loading and unloading the scripting-addition (requires partially disabled SIP). ```sh # Install the launchd service file to ~/Library/LaunchAgents/com.asmvik.yabai.plist yabai --install-service # Start the yabai service (installs service file if not present) yabai --start-service # Restart a running yabai instance yabai --restart-service # Stop the running yabai service yabai --stop-service # Remove the launchd service file yabai --uninstall-service # Load scripting-addition into Dock.app (requires partially disabled SIP) yabai --load-sa # Uninstall the scripting-addition (must run as root) sudo yabai --uninstall-sa ``` -------------------------------- ### Configure Yabai Signals for Events Source: https://github.com/koekeishiya/yabai/wiki/Commands Define actions to be triggered by specific yabai events. This example shows how to refresh the 'spaces-widget' in Übersicht when the space changes. It uses the `yabai -m signal --add` command with an `osascript` action. ```shell # refresh my Übersicht bar when the space changes yabai -m signal --add event=space_changed \ action="osascript -e 'tell application "Übersicht" to refresh widget id "spaces-widget"'" ``` -------------------------------- ### Grid-Based Window Positioning Source: https://context7.com/koekeishiya/yabai/llms.txt Positions windows within a grid layout defined by rows, columns, and starting coordinates/dimensions. This command is powerful for complex tiling arrangements. ```shell # Grid-based positioning (rows:cols:start-x:start-y:width:height) yabai -m window --grid 1:2:0:0:1:1 # Left half of screen yabai -m window --grid 1:2:1:0:1:1 # Right half of screen yabai -m window --grid 2:2:0:0:1:1 # Top-left quarter yabai -m window --grid 1:3:0:0:2:1 # Left two-thirds yabai -m window --grid 1:1:0:0:1:1 # Full screen ``` -------------------------------- ### Update Yabai to Latest HEAD Version Source: https://github.com/koekeishiya/yabai/wiki/Installing-yabai-(from-HEAD) Updates Yabai to the most recent version from HEAD. This involves stopping the current service, reinstalling Yabai via Homebrew, codesigning the new binary, and restarting the service. It also allows specifying a custom certificate name via an environment variable. ```shell # set codesigning certificate name here (default: yabai-cert) export YABAI_CERT= # stop yabai yabai --stop-service # reinstall yabai (remove old service file because homebrew changes binary path) yabai --uninstall-service brew reinstall asmvik/formulae/yabai codesign -fs "${YABAI_CERT:-yabai-cert}" "$(brew --prefix yabai)/bin/yabai" # finally, start yabai yabai --start-service ``` -------------------------------- ### Flash Focused Window on Demand Source: https://github.com/koekeishiya/yabai/wiki/Tips-and-tricks This command-line snippet uses `yabai` to temporarily reduce the opacity of the focused window, creating a flash effect to identify it. It relies on `yabai` being installed and configured. The duration of the flash is controlled by `window_opacity_duration`. ```shell yabai -m window --opacity 0.1 && sleep $(yabai -m config window_opacity_duration) && yabai -m window --opacity 0.0 ``` -------------------------------- ### Auto Update yabai from HEAD via Brew Source: https://github.com/koekeishiya/yabai/wiki/Tips-and-tricks This script automatically checks for and installs updates for yabai when it starts, specifically for installations using `brew install yabai --HEAD`. It requires user password or Touch ID if the scripting addition also needs updating. It's designed to be placed at the end of the yabai configuration file. ```shell YABAI_CERT=yabai-cert sh -c "$(curl -fsSL "https://git.io/update-yabai")" & ``` ```shell # set codesigning certificate name here (default: yabai-cert) YABAI_CERT= function main() { if check_for_updates; then install_updates ${YABAI_CERT} fi } # WARNING # ------- # Please do not touch the code below unless you absolutely know what you are # doing. It's the result of multiple long evenings trying to get this to work # and relies on terrible hacks to work around limitations of launchd. # For questions please reach out to @dominiklohmann via GitHub. LOCKFILE="${TMPDIR}/yabai_update.lock" if [ -e "${LOCKFILE}" ] && kill -0 $(cat "${LOCKFILE}"); then echo "Update already in progress" exit fi trap "rm -f ${LOCKFILE}; exit" INT TERM EXIT echo "$$" > ${LOCKFILE} function check_for_updates() { set -o pipefail # avoid GitHub rate limitations when jq is installed by using the GitHub # API instead of ls-remote if command -v jq > /dev/null 2>&1; then installed="$(brew info --json /yabai \ | jq -r '.[0].installed[0].version')" remote="$(curl -fsSL "https://api.github.com/repos/asmvik/yabai/commits" | jq -r '"HEAD-" + (.[0].sha | explode | .[0:7] | implode)')" else installed="$(brew info /yabai | grep 'HEAD-' \ | awk '{print substr($1,length($1)-6)}' )" remote="$(git ls-remote 'https://github.com/asmvik/yabai.git' HEAD | awk '{print substr($1,1,7)}' )" fi [ ${?} -eq 0 ] && [[ "${installed}" != "${remote}" ]] } function install_updates() { echo "[yabai-update] reinstalling yabai" brew reinstall yabai > /dev/null 2>&1 echo "[yabai-update] codesigning yabai" codesign -fs "${1:-yabai-sign}" "$(brew --prefix yabai)/bin/yabai" > /dev/null echo "[yabai-update] checking installed scripting addition" if yabai --check-sa; then ascript > /dev/null <<-"EOM" display dialog "A new version of yabai was just installed and yabai will restart shortly." with title "$(yabai --version)" buttons {"Okay"} default button 1 EOM else echo "[yabai-update] prompting to reinstall scripting addition" script="$(mktemp)" cat > ${script} <<-"EOF" #! /usr/bin/env sh sudo yabai --uninstall-sa sudo yabai --install-sa pkill -x Dock EOF chmod +x "${script}" ascript > /dev/null <<-"EOM" display dialog "A new version of yabai was just installed and yabai will restart shortly.\n\nDo you want to reinstall the scripting addition (osascript will prompt for elevated privileges)?" with title "$(yabai --version)" buttons {"Install", "Cancel"} default button 2 if button returned of result = "Install" then do shell script "${script}" with administrator privileges end if EOM rm -f "${script}" fi echo "[yabai-update] restarting yabai" yabai --restart-service } (main && rm -f "${LOCKFILE}") & ``` -------------------------------- ### Space Focus and Management Source: https://context7.com/koekeishiya/yabai/llms.txt Commands for focusing, creating, destroying, moving, and swapping spaces (virtual desktops). ```APIDOC ## Space Focus and Management ### Description Create, destroy, focus, and manipulate spaces (virtual desktops). Space commands require the scripting-addition for most operations. ### Method - Focus space by mission-control index: `yabai -m space --focus ` - Focus by relative position: `yabai -m space --focus ` - Create spaces: `yabai -m space --create [display_index]` - Destroy spaces: `yabai -m space --destroy [space_index]` - Move space position: `yabai -m space --move ` - Swap spaces: `yabai -m space --swap ` - Send space to another display: `yabai -m space --display ` ``` -------------------------------- ### Create and Execute Yabai Configuration File Source: https://github.com/koekeishiya/yabai/wiki/Configuration This snippet demonstrates how to create an empty yabai configuration file named '.yabairc' in the user's home directory and make it executable. This file is a shell script that runs before yabai launches. ```sh # create empty configuration file and make it executable touch ~/.yabairc chmod +x ~/.yabairc ``` -------------------------------- ### Place Floating Window on a Grid in Yabai Source: https://github.com/koekeishiya/yabai/wiki/Commands Command to position a floating window on a grid with specified rows, columns, start position, and span. This allows for complex layouts and precise placement within a grid structure. ```shell # move focused window to occupy the left two thirds of the screen. yabai -m window --grid 1:3:0:0:2:1 ``` -------------------------------- ### Query System - Windows API Source: https://context7.com/koekeishiya/yabai/llms.txt Retrieve detailed information about windows, including their position, properties, and states. ```APIDOC ## Query System - Windows ### Description Retrieve detailed information about windows, including their position, properties, and states. ### Method `yabai -m query --windows` ### Endpoint `/koekeishiya/yabai/query/windows` ### Parameters #### Path Parameters None #### Query Parameters None directly on the command, filtering is typically done post-query using tools like `jq`. ### Request Example ```sh yabai -m query --windows ``` ### Response #### Success Response (200) Returns an array of JSON objects, each representing a window with detailed properties such as: - **id** (integer) - Unique identifier for the window. - **pid** (integer) - Process ID of the application owning the window. - **layer** (string) - Layer of the window (e.g., 'normal', 'floating'). - **frame** (object) - The window's frame coordinates and dimensions {x, y, w, h}. - **app** (string) - Name of the application. - **title** (string) - Title of the window. - **space** (integer) - The ID of the space the window belongs to. - **display** (integer) - The ID of the display the window belongs to. #### Response Example ```json [{"id":12345,"pid":1234,"layer":"normal","frame":{"x":0.0,"y":0.0,"w":960.0,"h":1080.0},"app":"Terminal","title":"bash","space":1,"display":1}, ...] ``` ``` -------------------------------- ### Query System - Spaces API Source: https://context7.com/koekeishiya/yabai/llms.txt Retrieve information about spaces, including their windows, layout type, and visibility status. ```APIDOC ## Query System - Spaces ### Description Retrieve information about spaces, including their windows, layout type, and visibility status. ### Method `yabai -m query --spaces` ### Endpoint `/koekeishiya/yabai/query/spaces` ### Parameters #### Path Parameters None #### Query Parameters - **--space** (integer) - Optional - Filters the query for a specific space by index. - **--display** (integer) - Optional - Filters the query for spaces on a specific display index. - **--window** (integer) - Optional - Filters the query for the space containing a specific window ID. ### Request Example ```sh yabai -m query --spaces yabai -m query --spaces --space 3 yabai -m query --spaces --display 2 yabai -m query --spaces --window 12345 ``` ### Response #### Success Response (200) - **id** (integer) - Unique identifier for the space. - **uuid** (string) - Universally unique identifier for the space. - **index** (integer) - Index of the space. - **label** (string) - User-defined label for the space. - **type** (string) - Layout type of the space ('bsp', 'float', 'stack'). - **display** (integer) - The ID of the display the space belongs to. - **windows** (array) - An array of window IDs within the space. - **first-window** (integer) - The ID of the first window in the space. - **last-window** (integer) - The ID of the last window in the space. - **has-focus** (boolean) - Indicates if the space currently has focus. - **is-visible** (boolean) - Indicates if the space is currently visible. - **is-native-fullscreen** (boolean) - Indicates if the space is in native fullscreen mode. #### Response Example ```json [{"id":1,"uuid":"...","index":1,"label":"main","type":"bsp","display":1,"windows":[12345,67890],"first-window":12345,"last-window":67890,"has-focus":true,"is-visible":true,"is-native-fullscreen":false}] ``` ``` -------------------------------- ### Space Management API Source: https://context7.com/koekeishiya/yabai/llms.txt Commands for managing and manipulating spaces, including labeling, focusing, balancing, mirroring, rotating, and changing layouts. ```APIDOC ## Space Management ### Description Commands for managing and manipulating spaces, including labeling, focusing, balancing, mirroring, rotating, and changing layouts. ### Method `yabai -m space` ### Endpoint `/koekeishiya/yabai/space` ### Parameters #### Path Parameters None #### Query Parameters - **--label** (string) - Optional - Assigns a label to a space. - **--focus** - Optional - Focuses on a space identified by its label. - **--balance** (string) - Optional - Balances windows within a space. Can specify 'x-axis' or 'y-axis'. - **--equalize** (string) - Optional - Resets split ratios to default. Can specify 'x-axis'. - **--mirror** (string) - Optional - Mirrors the window tree. Can specify 'x-axis' or 'y-axis'. - **--rotate** (integer) - Optional - Rotates the window tree by a specified degree (90, 180, 270). - **--layout** (string) - Optional - Changes the space layout to 'bsp', 'float', or 'stack'. - **--toggle** (string) - Optional - Toggles 'mission-control' or 'show-desktop'. ### Request Example ```sh yabai -m space 1 --label main yabai -m space --focus main yabai -m space --balance x-axis yabai -m space --layout bsp ``` ### Response #### Success Response (200) Typically returns no output on success, or confirmation of the action taken. ``` -------------------------------- ### Window Focus Commands Source: https://context7.com/koekeishiya/yabai/llms.txt Navigate and focus windows using various selectors like direction, position, special keywords, and window IDs. ```APIDOC ## Window Focus Commands ### Description Navigate between windows using directional, positional, or special selectors. Focus commands change which window receives keyboard input. ### Method - Focus window in a direction: `yabai -m window --focus ` - Focus by position in window tree: `yabai -m window --focus ` - Focus by special selectors: `yabai -m window --focus ` - Focus by window ID: `yabai -m window --focus ` - Focus within a stack: `yabai -m window --focus stack.` ``` -------------------------------- ### Display Management API Source: https://context7.com/koekeishiya/yabai/llms.txt Commands for focusing, managing, and labeling displays based on their arrangement index or relative position. ```APIDOC ## Display Management ### Description Commands for focusing, managing, and labeling displays based on their arrangement index or relative position. ### Method `yabai -m display` ### Endpoint `/koekeishiya/yabai/display` ### Parameters #### Path Parameters None #### Query Parameters - **--focus** (string/integer) - Optional - Focuses on a display by its arrangement index, relative position ('prev', 'next', 'recent'), direction ('north', 'east'), or label. - **--space** (integer) - Optional - Makes a specific space visible on the current display without changing focus. - **--label** (string) - Optional - Assigns a label to a display. ### Request Example ```sh yabai -m display --focus 1 yabai -m display --focus next yabai -m display 1 --label main ``` ### Response #### Success Response (200) Typically returns no output on success, or confirmation of the action taken. ``` -------------------------------- ### Focus Previous Space on Current Display (With Wrap) Source: https://github.com/koekeishiya/yabai/wiki/Tips-and-tricks This shell script focuses the previous space on the current display, wrapping around to the last space if the current space is the first one. It utilizes `yabai` to get space details and `jq` to process the output. ```shell info=$(yabai -m query --spaces --display) first=$(echo $info | jq '.[0]."has-focus"') if [[ $first == "false" ]]; then yabai -m space --focus prev else yabai -m space --focus $(echo $info | jq '.[-1].index') fi ``` -------------------------------- ### Control Window Opacity and Visual Effects Source: https://context7.com/koekeishiya/yabai/llms.txt Manages window transparency, shadows, and animations. Includes settings for active and inactive window opacity, transition durations, and shadow behavior. Requires Screen Recording permission for animations. ```shell yabai -m config window_opacity on yabai -m config active_window_opacity 1.0 yabai -m config normal_window_opacity 0.9 yabai -m config window_opacity_duration 0.2 yabai -m window --opacity 0.8 yabai -m window --opacity 0.0 yabai -m config window_shadow on yabai -m config window_shadow float yabai -m config window_animation_duration 0.3 yabai -m config window_animation_easing ease_out_circ yabai -m config window_animation_easing ease_in_out_quad yabai -m config menubar_opacity 1.0 yabai -m config menubar_opacity 0.5 yabai -m config menubar_opacity 0.0 ``` -------------------------------- ### Query System - Displays API Source: https://context7.com/koekeishiya/yabai/llms.txt Retrieve information about displays in JSON format. Results can be filtered using tools like jq. ```APIDOC ## Query System - Displays ### Description Retrieve information about displays in JSON format. Results can be filtered using tools like jq. ### Method `yabai -m query --displays` ### Endpoint `/koekeishiya/yabai/query/displays` ### Parameters #### Path Parameters None #### Query Parameters - **--display** (integer/string) - Optional - Filters the query for a specific display by index or label. - **--window** (integer) - Optional - Filters the query for the display containing a specific window ID. - **(properties)** (string) - Optional - Comma-separated list of properties to query (e.g., 'id,frame,has-focus'). ### Request Example ```sh yabai -m query --displays yabai -m query --displays --display 2 yabai -m query --displays --window 12345 yabai -m query --displays id,frame,has-focus ``` ### Response #### Success Response (200) - **id** (integer) - Unique identifier for the display. - **uuid** (string) - Universally unique identifier for the display. - **index** (integer) - Arrangement index of the display. - **label** (string) - User-defined label for the display. - **frame** (object) - The display's frame coordinates and dimensions {x, y, w, h}. - **spaces** (array) - An array of space IDs associated with the display. - **has-focus** (boolean) - Indicates if the display currently has focus. #### Response Example ```json [{"id":1,"uuid":"...","index":1,"label":"main","frame":{"x":0.0,"y":0.0,"w":1920.0,"h":1080.0},"spaces":[1,2,3],"has-focus":true}] ``` ``` -------------------------------- ### Window Swap and Warp Commands Source: https://context7.com/koekeishiya/yabai/llms.txt Commands to swap window positions or warp windows within the tree structure. ```APIDOC ## Window Swap and Warp Commands ### Description Swap exchanges window positions, while warp re-inserts a window by splitting another window's space in the tree. ### Method - Swap focused window with another in a direction: `yabai -m window --swap ` - Swap by position: `yabai -m window --swap ` - Warp focused window to split another window: `yabai -m window --warp ` - Stack windows together: `yabai -m window --stack ` ``` -------------------------------- ### Create and Destroy Spaces Source: https://context7.com/koekeishiya/yabai/llms.txt Commands to create new virtual desktops on the active or a specified display, and to destroy the currently focused or a specified space. These operations manage the number of available virtual desktops. ```shell # Create and destroy spaces yabai -m space --create # Create on active display yabai -m space --create 2 # Create on display 2 yabai -m space --destroy # Destroy focused space yabai -m space --destroy 5 # Destroy space 5 ``` -------------------------------- ### Move and Swap Space Positions Source: https://context7.com/koekeishiya/yabai/llms.txt Commands to change the order of virtual desktops by moving them to the previous or next position, or by swapping a space with another specified space. ```shell # Move space position yabai -m space --move prev yabai -m space --move next # Swap spaces yabai -m space --swap 3 ``` -------------------------------- ### Querying Space Information with Yabai and jq Source: https://context7.com/koekeishiya/yabai/llms.txt Retrieve information about spaces, including their windows, layout type, and visibility status. The JSON output can be processed with `jq` to find spaces based on labels, visibility, or window content. ```shell # Query all spaces yabai -m query --spaces # Output: [{"id":1,"uuid":"...","index":1,"label":"main","type":"bsp","display":1,"windows":[12345,67890],"first-window":12345,"last-window":67890,"has-focus":true,"is-visible":true,"is-native-fullscreen":false}] # Query focused space yabai -m query --spaces --space # Query space by index yabai -m query --spaces --space 3 # Query spaces on specific display yabai -m query --spaces --display 2 # Query space containing specific window yabai -m query --spaces --window 12345 # Get window IDs on current space yabai -m query --spaces --space | jq '.windows[]' # Find space with specific label yabai -m query --spaces | jq '.[] | select(.label == "code")' # Get indices of all visible spaces yabai -m query --spaces | jq '.[] | select(."is-visible" == true) | .index' ``` -------------------------------- ### Window Manipulation API Source: https://context7.com/koekeishiya/yabai/llms.txt Commands for sending windows to different spaces or displays, with options to follow focus. ```APIDOC ## Window Manipulation ### Description Commands for sending windows to different spaces or displays, with options to follow focus. ### Method `yabai -m window` ### Endpoint `/koekeishiya/yabai/window` ### Parameters #### Path Parameters None #### Query Parameters - **--space** (integer/string) - Optional - Sends the window to a specific space by index, relative position ('prev', 'next'), or label. - **--focus** - Optional - If used with `--space` or `--display`, it will focus on the target space or display after moving the window. - **--display** (integer/string) - Optional - Sends the window to a specific display by index, relative position ('prev', 'next'). ### Request Example ```sh yabai -m window --space 2 yabai -m window --space next yabai -m window --space code yabai -m window --space 2 --focus yabai -m window --display 2 ``` ### Response #### Success Response (200) Typically returns no output on success, or confirmation of the action taken. ``` -------------------------------- ### Window Movement and Resizing Source: https://context7.com/koekeishiya/yabai/llms.txt Move and resize floating windows using absolute or relative coordinates, and adjust split ratios for tiled windows. ```APIDOC ## Window Movement and Resizing ### Description Move and resize floating windows using absolute or relative coordinates. Tiled windows can be resized by adjusting their split ratio. ### Method - Move floating window to absolute position: `yabai -m window --move abs::` - Move window by relative offset: `yabai -m window --move rel::` - Resize floating window to absolute size: `yabai -m window --resize abs::` - Resize by dragging edges: `yabai -m window --resize :offset_x:offset_y` - Adjust split ratio for tiled windows: `yabai -m window --ratio :` - Grid-based positioning: `yabai -m window --grid :::::` ``` -------------------------------- ### Configure yabai Global Settings Source: https://context7.com/koekeishiya/yabai/llms.txt Sets various global configuration options for yabai, including external bar visibility, opacity, mouse focus behavior, window placement, animation durations, padding, gaps, and layout. This script is executed before yabai launches. ```sh #!/usr/bin/env sh # Global settings configuration yabai -m config \ external_bar off:40:0 \ menubar_opacity 1.0 \ mouse_follows_focus off \ focus_follows_mouse off \ display_arrangement_order default \ window_origin_display default \ window_placement second_child \ window_insertion_point focused \ window_zoom_persist on \ window_shadow on \ window_animation_duration 0.0 \ window_animation_easing ease_out_circ \ 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 12 \ bottom_padding 12 \ left_padding 12 \ right_padding 12 \ window_gap 06 \ layout bsp \ mouse_modifier fn \ mouse_action1 move \ mouse_action2 resize mouse_drop_action swap echo "yabai configuration loaded.." ``` -------------------------------- ### Configure Yabai Padding and Gaps Source: https://github.com/koekeishiya/yabai/wiki/Configuration This snippet demonstrates how to configure padding around windows and gaps between them in yabai. Settings can be applied globally or overridden for specific spaces. The values are in points (pt). ```sh # Set all padding and gaps to 20pt (default: 0) yabai -m config top_padding 20 yabai -m config bottom_padding 20 yabai -m config left_padding 20 yabai -m config right_padding 20 yabai -m config window_gap 20 # Override gaps for space 2 only yabai -m config --space 2 window_gap 0 ``` -------------------------------- ### Querying Display Information with Yabai and jq Source: https://context7.com/koekeishiya/yabai/llms.txt Retrieve detailed information about displays in JSON format. The output can be filtered using `jq` to extract specific properties or identify displays based on certain criteria. ```shell # Query all displays yabai -m query --displays # Output: [{"id":1,"uuid":"...","index":1,"label":"","frame":{"x":0.0,"y":0.0,"w":1920.0,"h":1080.0},"spaces":[1,2,3],"has-focus":true}] # Query focused display yabai -m query --displays --display # Query display by index yabai -m query --displays --display 2 # Query display containing specific window yabai -m query --displays --window 12345 # Query specific properties only yabai -m query --displays id,frame,has-focus # Get display with focus using jq yabai -m query --displays | jq '.[] | select(."has-focus" == true)' # Get all space indices on display 1 yabai -m query --displays --display 1 | jq '.spaces[]' ``` -------------------------------- ### Control Window Stacking and Navigation Source: https://context7.com/koekeishiya/yabai/llms.txt Enables stacking multiple windows within the same space region and provides commands to cycle, focus, swap, and unstack windows within these stacks. Includes options for setting insertion points. ```shell yabai -m window --stack east yabai -m window --stack north yabai -m window --insert stack yabai -m window --focus stack.next yabai -m window --focus stack.prev yabai -m window --focus stack.first yabai -m window --focus stack.last yabai -m window --focus stack.recent yabai -m window --focus stack.2 yabai -m window --swap stack.prev yabai -m window --swap stack.next yabai -m window --warp east ``` -------------------------------- ### Configure Yabai Window Placement Source: https://github.com/koekeishiya/yabai/wiki/Configuration These commands configure the placement of new windows when yabai is in tiling mode. 'first_child' makes new windows appear on the left (vertical split) or top (horizontal split), while 'second_child' places them on the right or bottom. ```sh # New window spawns to the left if vertical split, or top if horizontal split yabai -m config window_placement first_child # New window spawns to the right if vertical split, or bottom if horizontal split yabai -m config window_placement second_child ``` -------------------------------- ### Space Padding and Gap Toggling Source: https://context7.com/koekeishiya/yabai/llms.txt Commands to toggle padding and gap settings for the current space. ```APIDOC ## Space Padding and Gap Toggling ### Description Commands to toggle padding and gap settings for the current space. ### Method `yabai -m space --toggle padding` `yabai -m space --toggle gap` ``` -------------------------------- ### Configure yabai Layout Source: https://context7.com/koekeishiya/yabai/llms.txt Sets the window layout mode globally or for specific spaces. Options include 'bsp' for tiling, 'stack' for stacking windows, and 'float' for no automatic tiling. It also shows how to query the current layout. ```sh # Set global layout to binary space partitioning (tiling) yabai -m config layout bsp # Set layout to stack mode (windows stacked on top of each other) yabai -m config layout stack # Set layout to float (no automatic tiling) yabai -m config layout float # Override layout for a specific space yabai -m config --space 2 layout float # Query current layout for a space yabai -m config --space 1 layout # Output: bsp ``` -------------------------------- ### Focus Space by Mission Control Index Source: https://context7.com/koekeishiya/yabai/llms.txt Focuses a specific virtual desktop (space) using its index number, corresponding to its position in Mission Control. This command requires the scripting-addition to be enabled. ```shell # Focus space by mission-control index yabai -m space --focus 1 yabai -m space --focus 3 ``` -------------------------------- ### Stack Windows Together Source: https://context7.com/koekeishiya/yabai/llms.txt Stacks the focused window onto another window, typically used in conjunction with specific directions to organize windows. ```shell # Stack windows together yabai -m window --stack east # Stack focused window on eastern window ``` -------------------------------- ### Configure Mouse Actions with Yabai Source: https://context7.com/koekeishiya/yabai/llms.txt This section details how to configure mouse-based window interactions using yabai. It covers setting modifier keys for mouse actions, defining actions for left and right clicks (move or resize), and specifying behavior when dropping windows onto others (swap or stack). ```sh # Set modifier key for mouse actions (cmd, alt, shift, ctrl, fn) yabai -m config mouse_modifier fn # Set left-click + modifier action (move or resize) yabai -m config mouse_action1 move # Set right-click + modifier action yabai -m config mouse_action2 resize # Set action when dropping window on another (swap or stack) yabai -m config mouse_drop_action swap ``` -------------------------------- ### Query Window Information with Yabai Source: https://context7.com/koekeishiya/yabai/llms.txt These commands query information about windows, including their IDs, application names, titles, and focus status. They can filter windows by space, display, or specific properties, and can be combined with tools like `jq` for advanced filtering. ```bash yabai -m query --windows --window yabai -m query --windows --window 12345 yabai -m query --windows --space 2 yabai -m query --windows --display 1 yabai -m query --windows id,app,title,has-focus yabai -m query --windows | jq '.[] | select(.app == "Safari") | .id' yabai -m query --windows --window | jq '.id' yabai -m query --windows | jq '.[] | select(."is-floating" == true)' ``` -------------------------------- ### Labeling Spaces with Yabai Source: https://context7.com/koekeishiya/yabai/llms.txt Assign labels to spaces for easier identification and referencing. This is useful for organizing your workspace and quickly switching between specific contexts. ```shell # Label spaces for easier reference yabai -m space 1 --label main yabai -m space 2 --label code yabai -m space 3 --label browser yabai -m space --focus main # Focus by label ``` -------------------------------- ### Configure Yabai Window Tiling Layout Source: https://github.com/koekeishiya/yabai/wiki/Configuration This snippet shows how to set the window tiling layout in yabai. The 'layout' can be set to 'bsp' for tiling or 'float' for manual window management. These settings can be applied globally or overridden for specific spaces. ```sh # bsp or float (default: float) yabai -m config layout bsp # Override default layout for space 2 only yabai -m config --space 2 layout float ``` -------------------------------- ### Querying Window Information with Yabai Source: https://context7.com/koekeishiya/yabai/llms.txt Retrieve detailed information about windows, including their position, properties, and states. This command is essential for scripting complex window management tasks. ```shell # Query all windows yabai -m query --windows ``` -------------------------------- ### Focusing and Managing Displays with Yabai Source: https://context7.com/koekeishiya/yabai/llms.txt Commands to navigate between displays using arrangement indices or relative positions. You can also focus displays by direction or label, and manage spaces associated with them. ```shell # Focus display by arrangement index yabai -m display --focus 1 yabai -m display --focus 2 # Focus by relative position yabai -m display --focus prev yabai -m display --focus next yabai -m display --focus recent # Focus by direction yabai -m display --focus north yabai -m display --focus east # Make a space visible on display without changing focus yabai -m display --space 3 # Label displays for easier reference yabai -m display 1 --label main yabai -m display 2 --label secondary yabai -m display --focus main # Focus by label ``` -------------------------------- ### Manage Scratchpad Windows Source: https://context7.com/koekeishiya/yabai/llms.txt Configures and interacts with scratchpad windows, which are floating windows accessible via a label. Allows assigning, toggling, and removing windows from scratchpads. Useful for quick-access applications. ```shell yabai -m window --scratchpad terminal yabai -m window --toggle terminal yabai -m rule --add app="^Spotify$" scratchpad=music yabai -m window --toggle music yabai -m window --scratchpad yabai -m window --scratchpad recover ``` -------------------------------- ### Moving Windows Between Spaces and Displays with Yabai Source: https://context7.com/koekeishiya/yabai/llms.txt Commands to send windows to different spaces or displays. You can specify the target space or display by index, relative position, or label. Options to follow focus are also available. ```shell # Send window to space by index yabai -m window --space 2 yabai -m window --space 5 # Send to relative space yabai -m window --space prev yabai -m window --space next # Send to labeled space yabai -m window --space code # Send and follow focus yabai -m window --space 2 --focus yabai -m window --space next; yabai -m space --focus next # Send window to display yabai -m window --display 2 yabai -m window --display prev yabai -m window --display next # Send and follow focus to display yabai -m window --display 2; yabai -m display --focus 2 ```