Created
August 14, 2024 17:34
-
-
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.
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/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