- Published on
Hyprland
301 words2 min read
Move Window to next empty Workspace
Script
#!/usr/bin/env bash
# Default dispatcher is 'movetoworkspace', but you can pass 'movetoworkspacesilent' as arg 1
dispatcher="${1:-movetoworkspace}"
# 1. Get the current workspace ID
curr_workspace=$(hyprctl activeworkspace -j | jq -r ".id")
# 2. Get a list of all currently occupied/active workspaces
# If a workspace ID is NOT in this list, it is empty.
occupied_workspaces=$(hyprctl workspaces -j | jq -r '.[].id')
# 3. Find the next available ID
# We start checking from (current + 1)
target_workspace=$((curr_workspace + 1))
while true; do
# Check if the target_workspace exists in the occupied list.
if ! echo "$occupied_workspaces" | grep -q -w "$target_workspace"; then
break
fi
# If it is occupied, increment and check the next one
((target_workspace++))
done
# 4. Dispatch the move command
hyprctl dispatch "${dispatcher}" "${target_workspace}"
Binds
bind = Alt, N, exec, ~/.config/hypr/hyprland/scripts/window_to_empty_workspace.sh movetoworkspacesilent
bind = Alt+Shift, N, exec, ~/.config/hypr/hyprland/scripts/window_to_empty_workspace.sh movetoworkspace