Skip to content

Instantly share code, notes, and snippets.

@senko
Created December 22, 2022 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save senko/2715b61f8e772e1f4d7eb2de0bc69806 to your computer and use it in GitHub Desktop.
Save senko/2715b61f8e772e1f4d7eb2de0bc69806 to your computer and use it in GitHub Desktop.
Shell script to toggle window with specified ID as visible/hidden on current workspace, or start the app if it's not running
#!/bin/bash
if test -z "$2"; then
echo "Usage: $0 <app_id> <command ...>"
exit 1
fi
app_id="$1"
shift
window_id=$(swaymsg -t get_tree | jq -r ".. | objects | select(.app_id==\"$app_id\") | .id")
if test -z "$window_id"; then
exec $@
fi
visible=$(swaymsg -t get_tree | jq -r ".. | objects | select(.app_id==\"$app_id\") | .visible")
if "$visible" == "true"; then
swaymsg "[app_id=\"$app_id\"] move to scratchpad"
else
swaymsg "[app_id=\"$app_id\"] move to workspace current"
swaymsg "[app_id=\"$app_id\"] focus"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment