Created
December 22, 2022 16:23
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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