This Bash script is part of a macOS window management system using Yabai. It moves the currently focused window to the next space to the right, automatically creating a new space if the window is already at the rightmost space.
- Primary function: Move the active window one space to the right
- Edge case handling: Creates a new space when at the rightmost position
- Focus management: Ensures the moved window remains focused after the operation
- Queries the current space and finds the next available space to the right
- Uses
jqto parse Yabai's JSON output for accurate space information - Handles edge cases when there's no space to the right
- When at the rightmost space, automatically creates a new space
- Moves the window to the newly created space
- Maintains user focus on the moved window
- Logs all operations through a centralized
log_helper.shscript - Tracks before/after states for debugging
- Records window IDs, space indices, and display information
- Validates window ID retrieval before attempting operations
- Exits gracefully with error logging if no window is focused
- Uses proper null checks for JSON parsing
/opt/homebrew/bin/yabai- Yabai window manager/opt/homebrew/bin/jq- JSON processor for parsing Yabai querieslog_helper.sh- Centralized logging utility (same directory)
- Initial State Capture: Logs current window, space, and display
- Window Identification: Gets the focused window's ID
- Space Detection: Finds the next space to the right
- Movement Logic:
- If next space exists: Move window directly
- If at rightmost space: Create new space, then move
- Focus Restoration: Ensures the moved window stays focused
- Final State Logging: Records the end state for verification
log_state(): Captures and logs the current window management statefocus_window(): Refocuses a specific window by ID with verification
- Uses 0.1-second delays after space changes to ensure Yabai completes operations
- String comparison for empty space detection uses literal
'""'check - Window focus is explicitly restored after movement to handle Yabai quirks
~/.config/scripts/move_window_right.shTypically bound to a keyboard shortcut via Karabiner-Elements or similar tools.
Part of a larger window management system with complementary scripts:
move_window_left.sh- Move window to previous spacespace_right.sh- Focus next space without moving windowsremove_empty_spaces.sh- Clean up unused spaces
Logs are written via log_helper.sh with structured format:
- START/END: Script lifecycle events
- INFO: Informational messages
- ACTION: Yabai commands being executed
- ERROR: Error conditions
- DEBUG: Detailed state information