#!/usr/bin/env sh # Get two outputs, visible workspaces and focused workspace output1=$(swaymsg -t get_outputs --raw | jq '.[0].name' -r) output2=$(swaymsg -t get_outputs --raw | jq '.[1].name' -r) workspace1=$(swaymsg -t get_outputs --raw | jq '.[0].current_workspace' -r) workspace2=$(swaymsg -t get_outputs --raw | jq '.[1].current_workspace' -r) workspace_active=$(swaymsg -t get_workspaces | jq -r '.[] | select(.focused==true).name') # If any of the outputs doesn't have a workspace, do nothing if [ "$workspace1" = null ] || [ "$workspace2" = null ]; then exit 0 else # If script is provided with `follow` argument, then follow focused workspace if [ "$1" = "follow" ]; then if [ "$workspace1" = "$workspace_active" ]; then swaymsg move workspace to output "$output2" swaymsg workspace "$workspace2" swaymsg move workspace to output "$output1" swaymsg workspace "$workspace2" else swaymsg workspace "$workspace1" swaymsg move workspace to output "$output2" swaymsg workspace "$workspace2" swaymsg move workspace to output "$output1" fi # Else focus stays with focused output else if [ "$workspace1" = "$workspace_active" ]; then swaymsg move workspace to output "$output2" swaymsg workspace "$workspace2" swaymsg move workspace to output "$output1" else swaymsg workspace "$workspace1" swaymsg move workspace to output "$output2" swaymsg workspace "$workspace2" swaymsg move workspace to output "$output1" swaymsg workspace "$workspace1" fi fi fi