You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello! iye.cba . A few days ago I got this script on github. I like the script very much. It taught me a lot, gave me another idea to solve the problem. But I am sorry that I do not like some places in the script.
So I modified some code that makes the script more powerful and more elegant.
#!/bin/bash# lightsOn.sh# Copyright (c) 2013 iye.cba at gmail com# url: https://github.com/iye/lightsOn# This script is licensed under GNU GPL version 2.0 or above
flash_detection=1
mplayer_detection=1
vlc_detection=1
minitube_detection=1
gnome_mplayer_detection=1
smplayer_detection=1
totem_detection=1
delay_progs=()
displays=""whileread id
do
displays="$displays$id"done<<(xvinfo | sed -n 's/^screen #\([0-9]\+\)$/\1/p')# I think "pidof name" is better than "pgrep -lfc name |grep -wc name". It only output the PIDs when detects the process,# but output nothing when no process.Most importantly, it is shorter.if [ `pidof xscreensaver` ];then
screensaver=xscreensaver
elif [ `pidof gnome-screensaver` ];then# Most desktop enviromments use gnome-screensaver.
screensaver=gnome-screensaver
elif [ `pidof cinnamon-screensaver` ];then# cinnamon desktop enviromment is getting more and more popular.
screensaver=cinnamon-screensaver
elif [ `pidof kscreensaver` ];then# This can not effect on latest KDE version.
screensaver=kscreensaver
elif [ -f$HOME/.kde*/share/config/kscreensaverrc ] && [ -z`grep -iw "enabled=false"$HOME/.kde*/share/config/kscreensaverrc` ];then#Effect on new KDE version.
screensaver=kscreensaver
else
screensaver=None
echo"No screensaver detected"ficheckDelayProgs()
{
forprogin"${delay_progs[@]}";doif [ `pidof "$prog"` ];thenecho"Delaying the screensaver because a program on the delay list, \"$prog\", is running..."
delayScreensaver
breakfidone
}
checkFullscreen()
{
fordisplayin$displaysdo
activ_win_id=`DISPLAY=:0.${display} xprop -root _NET_ACTIVE_WINDOW`
activ_win_id=${activ_win_id:40:9}if [ "$activ_win_id"="0x0" ];then# Skip invalid window ids (It returns "0x0" when ScreenSaver is actived)continuefi
isActivWinFullscreen=`DISPLAY=:0.${display} xprop -id $activ_win_id| grep _NET_WM_STATE_FULLSCREEN`if [ "$isActivWinFullscreen" ];then
isAppRunning
var=$?if [[ $var-eq 1 ]];then
delayScreensaver
fifidone
}
isAppRunning()
{
#Get PID of active window, I think it makes the code easier.
activ_win_pid=`xprop -id $activ_win_id| grep "_NET_WM_PID(CARDINAL)"`
activ_win_pid=${activ_win_pid##* }if [ $flash_detection== 1 ];thenif [[ `lsof -p $activ_win_pid| grep flashplayer.so` ]];then# match all browers (which use libflashplayer.so , libpepflashplayer.so & operapluginwrapper-native)return 1
fifiif [ $mplayer_detection== 1 ];thenif [[ `ps p $activ_win_pid o comm=`="mplayer" ]];then# Which is more simple and accurate.return 1
fifiif [ $vlc_detection== 1 ];thenif [[ `ps p $activ_win_pid o comm=`="vlc" ]];thenreturn 1
fifiif [ $minitube_detection== 1 ];thenif [[ `ps p $activ_win_pid o comm=`="minitube" ]];thenreturn 1
fifiif [ $gnome_mplayer_detection== 1 ];then# It is easy to add video player detection.if [[ `ps p $activ_win_pid o comm=`="gnome-mplayer" ]];thenreturn 1
fifiif [ $smplayer_detection== 1 ];thenif [[ `ps p $activ_win_pid o comm=`="smplayer" ]];thenreturn 1
fifiif [ $totem_detection== 1 ];thenif [[ `ps p $activ_win_pid o comm=`="totem" ]];thenreturn 1
fifireturn 0
}
delayScreensaver()
{
if [ "$screensaver"=="xscreensaver" ];then
xscreensaver-command -deactivate > /dev/null
elif [ "$screensaver"=="gnome-screensaver" ];then
gnome-screensaver-command --deactivate > /dev/null # It is similar to xscreensaver.elif [ "$screensaver"=="cinnamon-screensaver" ];then
cinnamon-screensaver-command --deactivate > /dev/null # I have not tried, but I guess it do so.elif [ "$screensaver"=="kscreensaver" ];then
qdbus org.freedesktop.ScreenSaver /ScreenSaver SimulateUserActivity > /dev/null
fi
dpmsStatus=`xset -q | grep -ce 'DPMS is Enabled'`if [ $dpmsStatus== 1 ];then
xset -dpms
xset dpms
fi
}
delay=$1if [ -z"$1" ];then
delay=50
fiif [[ $1=*[^0-9]* ]];thenecho"The Argument \"$1\" is not valid, not an integer"echo"Please use the time in seconds you want the checks to repeat."echo"You want it to be ~10 seconds less than the time it takes your screensaver or DPMS to activate"exit 1
fiwhiletruedo
checkDelayProgs
checkFullscreen
sleep $delaydoneexit 0
The text was updated successfully, but these errors were encountered:
Sadly, this does not work for Cinnamon 2.0 (Mint 16 Petra, based on Ubuntu 13.10), BUT it doesn't display the "no screensaver" error message. Something must be wrong, but I can't tell yet, it should work...
Hello! iye.cba . A few days ago I got this script on github. I like the script very much. It taught me a lot, gave me another idea to solve the problem. But I am sorry that I do not like some places in the script.
So I modified some code that makes the script more powerful and more elegant.
The text was updated successfully, but these errors were encountered: