Skip to content

Instantly share code, notes, and snippets.

@iguanajuice
Created August 14, 2024 17:34
Show Gist options
  • Save iguanajuice/4b34ef2d93a53b7e1e91ddeb70768c4e to your computer and use it in GitHub Desktop.
Save iguanajuice/4b34ef2d93a53b7e1e91ddeb70768c4e to your computer and use it in GitHub Desktop.
Run a sway command when a window appears; like `for_window` but temporary.
#!/bin/sh
if [ $# -ne 2 ]
then
echo "Usage: swaywait [target] [command]"
exit 1
fi
TARGET=$1
COMMAND=$2
swaymsg -t subscribe -m '["window"]' | while read line
do
CON=`echo $line | jq -r 'select(.change=="new").container'`
APPID=`echo $CON | jq -r '.app_id'`
CLASS=`echo $CON | jq -r '.window_properties.class'`
CONID=`echo $CON | jq -r '.id'`
if [ "$APPID" = "$TARGET" ] || [ "$CLASS" = "$TARGET" ]
then
swaymsg "[con_id=$CONID] $COMMAND"
kill -PIPE 0
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment