Skip to content

Instantly share code, notes, and snippets.

@m-GDEV
Created August 21, 2024 01:13
Show Gist options
  • Save m-GDEV/22fbcaa0d5d58e8220e93bc1f8a8d85a to your computer and use it in GitHub Desktop.
Save m-GDEV/22fbcaa0d5d58e8220e93bc1f8a8d85a to your computer and use it in GitHub Desktop.
# This program gets a list of all windows in i3 and based on the name of the window it moves them to a specific workspace
#!/bin/bash
# This program gets a list of all windows in i3 and based on the name of the window it moves
# them to a specific workspace
# Get workspace names: i3-msg -t get_workspaces
# https://jsonselector.com helps
WINDOWS=$(i3-msg -t get_tree | jq '[.nodes[1].nodes[1].nodes[] | select(.type="workspace") | .nodes[] | {id: .id, name: .window_properties.instance}]')
echo -n "$WINDOWS" | jq -c '.[]' | while read -r window
do
window_id=$(echo -n "$window" | jq '.id')
# jq leaves surrouding quotation marks
window_name=$(echo -n "$window" | jq '.name' | sed 's/"//g')
echo "$window_id"
echo "$window_name"
case "$window_name" in
# don't do anything for firefox since it can be in any workspace
Navigator)
;;
spotify)
i3-msg "[con_id=$window_id]" move container to workspace '4:🎧'
;;
xfce4-taskmanager)
i3-msg "[con_id=$window_id]" move container to workspace '5:📊'
;;
beeper)
i3-msg "[con_id=$window_id]" move container to workspace '6:💬'
;;
steamwebhelper)
i3-msg "[con_id=$window_id]" move container to workspace '8:🕹️'
;;
lutris)
i3-msg "[con_id=$window_id]" move container to workspace '8:🕹️'
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment