Bash: Temporarily Turn Off Screen Locking

Bash, PHP, etc
F-3000
Xfegrosh
Posts: 142
Joined: 30 Jun 2009, 23:41

Bash: Temporarily Turn Off Screen Locking

Post by F-3000 » 05 May 2010, 21:02

Prologue
At my "primary home", there's two kids, younger being merely 11y old, it's pretty clear that it's a good thing that my laptop's screen goes locked when screensaver (which just blanks the screen) kicks in. At my "secondary home" (where I sadly spend more time than at first mentioned) there's no threat to my privacy, and more importantly, no need to worry that some silly child goes messing around with my work, the locking-option is more of hindrance than use. Especially when I may have two computers running simultaneously, meaning that the laptop's screensaver really may blank the screen. While I got the IM (Instant Message) -applications (Pidgin & Skype) open on the laptop, it's clear that reading my girlfriend's (jokingly?) "status-reports" gets a tad pain if I'm playing a game on my Mac - if I have to type my password every freaking time after the screensaver jumps in. And since gnome-screensaver takes care of more than just the screensaver, I can't just simply drop it out.

Script
Save the script in a text-file, and change it's permissions to allow executing. Then you can easily make a launcher for it.

Code: Select all

#!/bin/bash
teSt=`gconftool-2 --direct --config-source xml:readwrite:$HOME/.gconf --get /apps/gnome-screensaver/lock_enabled`
[ "$teSt" = "true" ] && teSt=false || teSt=true
gnome-screensaver-command --exit
gconftool-2 --direct --config-source xml:readwrite:$HOME/.gconf --type bool --set /apps/gnome-screensaver/lock_enabled $teSt
gnome-screensaver </dev/null >/dev/null 2>&1 &
echo "Screen locking set to $teSt"
exit 0
If you want to make a launcher that tells you what's going on, set the launcher to run in terminal, and include this line just above exit:

Code: Select all

/path/to/your/pause-script
This assumes that you have saved this bash-script or have similar of your own making.

And to turn the lock automatically back on when you close the computer, you could save this bash-script in /etc/rc6.d/ with name K99lock_on (for example). (NOTE! This does not work for me for a reason I don't know...)

Code: Select all

#!/bin/bash
teSt=`gconftool-2 --direct --config-source xml:readwrite:$HOME/.gconf --get /apps/gnome-screensaver/lock_enabled`
if [ "$teSt" = "false" ]
then
gnome-screensaver-command --exit
gconftool-2 --direct --config-source xml:readwrite:$HOME/.gconf --type bool --set /apps/gnome-screensaver/lock_enabled true
fi
exit 0
Postscript
Something that amuses me: Before I started writing this article, the script was PHP-script, and the "lock_on" was less sophisticated.

Sources:
http://live.gnome.org/GnomeScreensaver/ ... dQuestions
http://en.kioskea.net/faq/3348-ubuntu-e ... d-shutdown
http://www.unix.com/shell-programming-s ... mmand.html
http://www.overclockers.com/forums/show ... p?t=659006

F-3000
Xfegrosh
Posts: 142
Joined: 30 Jun 2009, 23:41

Re: Bash: Temporarily Turn Off Screen Locking

Post by F-3000 » 02 Dec 2013, 22:53

UPDATE

Although this script is irrelevant to me by these days, and I don't even know whether this works with latest GNOME, I updated it a bit regardless.

In first script changed absolute paths to .gconf from /home/user to $HOME.

In second script changed path to .gconf from /home/$USER to $HOME. $USER (and now $HOME) could be the reason why second script wasn't working.

In first script changed that long if/then/else/fi check, that did set $teSt2, into current shorter version that simply flips $teSt from true to false and vice versa. [ "$teSt" = "true" ] && teSt=false || teSt=true

Added new source: http://www.overclockers.com/forums/show ... p?t=659006