Neue, stark verbesserte Version, die zusätzlich checkt, ob das aktive Fenster im Vollbildmodus ist oder Sound läuft und dann ebenfalls die idlezeit resettet. Außerdem werden die checks nur ausgeführt, wenn die idlezeit einen Mindestwert erreicht. Der (unzuverlässige) Check, ob die Sitzung noch läuft, entfällt nun.
Benötigte Pakete (s. auch Skript):
sudo apt-get install xprintidle libnotify-bin procps x11-utils coreutils inotify-tools
Das Skript:
#!/bin/bash
# (yet another) small script to reset X idletime and by that inhibit
# screensaver/powersaver when specific applications run, the active
# window is in fullscreen mode, or any sound is playing for more or
# equal 10 seconds.
# Please share it, if you find it useful!
# required packages: xprintidle libnotify-bin procps x11-utils coreutils inotify-tools
# Examples:
# flash in firefox: /usr/lib/firefox/plugin-container
# flash in iceweasel: plugin-containe
# banshee: banshee
# vlc: vlc
# Virtualbox: VirtualBox
# With the following command you can find out the process name of a the active window (6 seconds delay); xdotool must be installed:
# sleep 6 && cat /proc/$(xdotool getwindowpid $(xdotool getwindowfocus))/comm
# seperate applications with |
applications='VirtualBox' # remove comment in loop at bottom to take effect
# how many seconds sound has to play, until idletimereset gets active
maxsoundplaytime=10 # 10 could be a good value
# sleepingtime (every n seconds is checked, if one of the above applications is running
sleepingtime=48 # 48 could be a good value, DO NOT choose less than 4...
########################################################################################################
function applicationcheck
{
if pgrep -u $i_am -f "$applications" >/dev/null ; then # is one of the above apps, owned by current user, running?
eval $idletimereset
echo "one or more of the following applications reset the idletime: $applications"
notify-send -i dialog-information "$powermanager_deactivated"
sleep $sleepingtime
while pgrep -u $i_am -f "$applications" >/dev/null >/dev/null ; do
echo "one or more of the following applications reset the idletime: $applications"
eval $idletimereset
sleep $sleepingtime
done
notify-send -i dialog-information "$powermanager_activated"
else
echo "$applications is/are NOT running!"
fi
}
function fullscreencheck
{
active_window=$(xprop -id $(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2) _NET_WM_NAME)
active_window=${active_window##*= \"}
active_window=${active_window%\"}
if xprop -name "$active_window" _NET_WM_STATE | grep -q _NET_WM_STATE_FULLSCREEN ; then
eval $idletimereset
echo "active window is in fullscreen, idletime reset!"
notify-send -i dialog-information "$powermanager_deactivated"
sleep $sleepingtime
while xprop -name "$active_window" _NET_WM_STATE | grep -q _NET_WM_STATE_FULLSCREEN ; do
eval $idletimereset
echo "active window is in fullscreen, idletime reset!"
sleep $sleepingtime
done
notify-send -i dialog-information "$powermanager_activated"
else
echo "active window is NOT in fullscreen!"
fi
}
function soundcheck
{
soundplaytime=0
while eval $soundsystemcheck > /dev/null && [ $soundplaytime -lt $maxsoundplaytime ] ; do
echo "sound is playing..."
sleep 2
soundplaytime=$(($soundplaytime + 2))
done
if [ $soundplaytime -ge $maxsoundplaytime ] ; then
echo "sound has been playing for more or equal $maxsoundplaytime sec!" # and so, most probably, no system sound or similar has been registered
eval $idletimereset
echo "idletime reset!"
notify-send -i dialog-information "$powermanager_deactivated"
sleep $sleepingtime
while eval $soundsystemcheck > /dev/null; do
eval $idletimereset
echo "sound is playing, idletime reset!"
sleep $sleepingtime
done
notify-send -i dialog-information "$powermanager_activated"
else
echo "NO sound is playing!"
fi
}
# main..
displaynumber=$DISPLAY
displaynumber=${displaynumber%.*}
displaynumber=${displaynumber#*:}
if test -e /tmp/.X11-unix/X$displaynumber ;then # exit if not running X..
echo "Your xserver's displaynumber: $displaynumber"
else
echo "Fatal! Cannot find a file in /tmp/.X11-unix/X$displaynumber! Are you running X?"
notify-send -t 0 -i dialog-information "idletimereset kann so leider nicht funktionieren..."
exit 1
fi
xprintidle_sleepingtime=$(($sleepingtime * 500 - 1000)) # 1000/2 because in worst case it waits for (almost) twice the sleepingtime
i_am=$(whoami)
idletimereset="xset s reset" # the actual idletime reset command
powermanager_activated="Energieverwaltung wieder aktiviert"
powermanager_deactivated="Energieverwaltung deaktiviert"
# detect which (if any) soundsystem is running:
if pulseaudio --check ; then
echo "your session is using pulseaudio, using it for sound detection!"
soundsystemcheck="pactl list | grep RUNNING"
elif ! dpkg -s alsa-base |grep installed ; then
echo "Could not find alsa-base sound system, cannot use the sound-detect function"
soundsystemcheck="could_not_find_a_soundsystem!"
else
echo "pulseaudio NOT detected but alsa-base seems to be installed, using fuser /dev/snd/timer for sound detection!"
soundsystemcheck="fuser /dev/snd/timer"
fi
echo "start loop"
while sleep $sleepingtime; printf "\n----------------------\n" ; do
if [ $(xprintidle) -le $xprintidle_sleepingtime ] ; then # only get active, if the user is actually idle
echo "the user has not been idle for more than $(($sleepingtime / 2 - 1 )) seconds, no action applied."
else
# applicationcheck # remove comment to take effect
fullscreencheck
soundcheck
fi
done &
loopPID=$!
inotifywait /tmp/.X11-unix/X$displaynumber
kill -SIGTERM $loopPID
echo "xsession has ended, exiting"
exit 0
Wenn ihr etwas besser (oder anders..) machen würdet, fühlt euch gern frei, es mir mitzuteilen (da ich, wie man sieht, noch Anfänger bin)
Gruß
spawn