Created
April 25, 2025 09:40
-
-
Save bdombro/a0efab41eec61e9996d9b230b0c273dd to your computer and use it in GitHub Desktop.
steam_window_watcher_cronjob.sh
This file contains hidden or 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 | |
set -e | |
# Depends on https://extensions.gnome.org/extension/4724/window-calls/ | |
# Add to crontab: | |
# touch /tmp/www.log | |
# crontab -e | |
# * * * * * export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus && /home/brian/dev/linux/window_watcher_cronjob.sh >> /tmp/wwc.log 2>&1 | |
# V1 at bottom -- checks if window was opened and now closed | |
# WHy V2 is better? pkill is a noop if no match, so KISS | |
# V2 - kill if window not open | |
v2() { | |
state=$(/usr/bin/gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/Windows --method org.gnome.Shell.Extensions.Windows.List) | |
steam_is_open=$(echo "$state" | grep "Steam" || true) | |
if [[ -z "$steam_is_open" ]]; then | |
# echo `date` - killing | |
pkill steam | |
else | |
: # echo `date` - nokilling | |
fi | |
} | |
v2 | |
# V1 - kill if window was opened and now closed | |
v1() { | |
CACHE_MEM_FILE=/dev/shm/window_watcher_last | |
touch $CACHE_MEM_FILE | |
last=$(< $CACHE_MEM_FILE) | |
next=$(gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/Windows --method org.gnome.Shell.Extensions.Windows.List) | |
steam_is_open=$(echo "$next" | grep "Steam") | |
steam_was_open=$(echo "$last" | grep "Steam") | |
if [[ -n "$steam_is_open" ]]; then | |
: # Steam is open | |
echo open | |
elif [[ -n "$steam_was_open" ]]; then | |
#pkill steam # Steam exited | |
echo closed | |
fi | |
last=$next | |
printf '%s' "$next" > $CACHE_MEM_FILE | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment