LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Desktop (http://www.linuxquestions.org/questions/linux-desktop-74/)
-   -   Disable KDE4 screensaver while watching a movie (http://www.linuxquestions.org/questions/linux-desktop-74/disable-kde4-screensaver-while-watching-a-movie-4175471090/)

laitcg 07-27-2013 12:06 AM

Disable KDE4 screensaver while watching a movie
 
My KDE screen saver is set for 15 minutes and this bash script is in my Autostart for KDE4.

It simulates user activity every 10 minutes vice disable/enable the screensaver.

It uses a single line of program names separated by spaces. Enjoy. ;)

Code:

#!/bin/bash
# Copyright 2013, Jack S. Lai, Waianae, HI
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# Place this script in your KDE Startup. My Screen saver is set for 15 min.

# Space seperated list of programs to look for:
programs="vlc mplayer"
# Add your browser EG: 'firefox' if you use it for flash movies

sleep 600        # wait 10 minutes to check as we just started KDE
for pgm in ${programs}; do        # Check list of programs one by one
    if ps axo comm | grep -q ${pgm} ;then # Is a program running?
        # Yes, simulate user activity vice shutting down the screen saver
        qdbus org.kde.screensaver /ScreenSaver SimulateUserActivity
        break        # All done, we had at least one program running.
    fi
done
exec $0 $*        # Restart this script


jdackle 07-27-2013 08:48 AM

Nice script!

But I'm replying on the subject of the copyrights.
I've done a similar set of scripts (with the help of xl) and posted it here: http://www.linuxquestions.org/questi...ns-4175468270/ (current scripts at post #5).
They're meant to be used with XFCE, not KDE and intended to prevent the computer from suspending (not blanking the screen, for my purposes kepping the screensaver active is actually a good thing). But the rational is basically the same as for your script.

I can still work a lot on it and one thing I was thinking about is the way it checks for active programs that should prevent the computer from suspending. I'm doing it through an "if ( pgrep -l program1 ) || ( pgrep -l program2 ) || ..." condition but your way seems much more efficient.

So my question is: can I just take that part of your script (the "programs="prog1 prog2" + modified "for" loop) and add a modified "copyright" notice after what I currently have, such as (proposed addition in bold):
Code:

# Script suggested by user "xl" at LinuxQuestions.org in reply to a question of mine (JDAckle):
# XFCE (or related) Power Management "Inactivity" Settings/Exceptions
# http://www.linuxquestions.org/questions/linux-desktop-74/xfce-or-related-power-management-inactivity-settings-exceptions-4175468270/
# 02/07/2013 to 07/07/2013
# Process-running check modified according to the way Jack S. Lai coded his own  "Disable KDE4 screensaver while watching a movie" script, posted at http://www.linuxquestions.org/questions/linux-desktop-74/disable-kde4-screensaver-while-watching-a-movie-4175471090/#post4997687 (27/07/2013, 06:06 GMT

Thank you kindly,
Jean D. Ackle

laitcg 07-27-2013 03:12 PM

Quote:

Originally Posted by jdackle (Post 4997855)
Nice script!

So my question is: can I just take that part of your script (the "programs="prog1 prog2" + modified "for" loop) and add a modified "copyright" notice after what

You can take any PART of the script as needed w/out copyright inclusion. The script as a whole is the only thing copyrightable. But I do appreciate the mention :)

jdackle 07-27-2013 05:19 PM

Thank you!
Will be glad to make the mention! ;)

EDIT: Done!

laitcg 10-31-2013 01:32 PM

v1.1 10/31/13 - added "--sort -pcpu" to make the search quicker.

Code:

#!/bin/bash
# Copyright 2013, Jack S. Lai, Waianae, HI
# All rights reserved.
#
# v1.1 10/31/13 - added "--sort -pcpu" to make the search quicker.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# Place this script in your KDE Startup. My Screen saver is set for 15 min.

# Space seperated list of programs to look for:
programs="vlc mplayer"
# Add your browser EG: 'firefox' if you use it for flash movies

sleep 600        # wait 10 minutes to check as we just started KDE
for pgm in ${programs}; do        # Check list of programs one by one
    if ps axo comm --sort -pcpu | grep -q ${pgm} ;then # Is a program running?
        # Yes, simulate user activity vice shutting down the screen saver
        qdbus org.kde.screensaver /ScreenSaver SimulateUserActivity
        break        # All done, we had at least one program running.
    fi
done
exec $0 $*        # Restart this script



All times are GMT -5. The time now is 01:32 PM.