[ATrpms-users] gnome-screensaver with mythtv?
Jeffrey J. Kosowsky
atrpms at kosowsky.org
Wed Dec 30 16:56:31 CET 2009
Jeffrey J. Kosowsky wrote at about 04:34:45 -0500 on Wednesday, December 30, 2009:
> I was hoping that there would be a cleaner way than using a
> wrapper. It would be great if you could specify a list of programs
> (either via a config file or via a gui) that gnome-screensaver would
> check before activating.
>
> But if I need to do a wrapper, it seems like I could do a similar
> thing with gnome-screensaver.
>
> If you want the analog of the xscreensaver script, you can just do:
>
> ----------------------------------------------------------------
> #!/bin/bash
> gnome-screensaver-command -exit
> mythfrontend
> gnome-screensaver
> ----------------------------------------------------------------
>
> However, if you want something a little fancier and more robust you
> can use the '--inhibit' switch and also add a trap to ensure that the
> inhibition is removed (and the screensaver restored) even if you kill
> the script and it exits non-naturally. The trap probably has more
> error checking than necessary, but why not be paranoid...
>
> Note the use of "gnome-screensaver-command --inhibit" together with
> using the trap to selectively only kill the corresponding process on
> termination means that you can have several wrapper scripts for
> multiple programs that independently inhibit the screensaver such that
> the screensaver only can activate once *all* the programs terminate.
>
> -----------------------------------------------------------------------
> #/bin/bash
> #Wrapper to inhibit gnome-screensaver when launching mythfrontend
> #Jeff Kosowsky
>
> function killonexit ()
> {
> procs=$(pgrep -d ' ' -u $USER -f "$command")
> [[ -n $pid && "$procs" =~ $pid ]] && kill -KILL $pid
> }
>
> trap killonexit INT EXIT
>
> command='gnome-screensaver-command --inhibit --application-name="mythfrontend" --reason="Mythfrontend running..."'
>
> $command &
> pid=$!
> mythfrontend
>
> -------------------------------------------------------------------------
Here is a more general wrapper that you can use to *wrap* any program
without *any* modification. If you want to wrap the program
'myprogram' all you have to do is rename the following script as
${prefix}myprogram or link to it (where $prefix='j' by default but can
be almost any string). Nothing inside the script ever needs to be
modified. The program you want to run needs to be in your path.
----------------------------------------------------------------------------
#/bin/bash
#Wrapper to inhibit gnome-screensaver and launch the program 'basename'
#minus the leading '$prefix''.
#Specifically, to wrap any program, just hard (or soft link) this
#with the string '$prefix' prefixed to the desired program you want to wrap.
#
#Jeff Kosowsky - December 2009
prefix="j"
basename=${0##*/}
progname=${basename#$prefix} #Run as 'basename' minus the leading '$prefix'
if [ "$progname" = "$basename" ] || ! which $progname >&/dev/null; then
echo "Error: target '$progname' not in path..."
exit 1
fi
function removeinhibit () # Kill 'gnome-screensaver-command --inhibit'
{
procs=$(pgrep -d ' ' -u $USER -f "$command")
[[ -n $pid && "$procs" =~ $pid ]] && kill -KILL $pid
}
trap removeinhibit INT EXIT
command="gnome-screensaver-command --inhibit --application-name=\"$progname\" --reason=\"${progname^[a-z]} running...\""
$command & #Inhibit gnome-screensaver
pid=$!
$progname $@ # Run program...
More information about the atrpms-users
mailing list