Stop touching my laptop!
calendar Dec. 24, 2015   category  bash , scripting , gnome-shell   comments  comments

Co-workers who think they're funny/smart, because you've accidently left your screen unlocked, and altering your background, sending out mails and generally being an ass. We all know them. In the GNOME2 days there was the 'free the fish' joke, which was quite harmless. Nowadays GNOME3 doesn't have that anymore and people start causing havoc to 'teach' you to lock your screen.

Don't get me wrong, not locking your screen is a no-go and marks you as an incompetent noob who shouldn't be allowed to handle sensitive information, but that's not my point. My point is that you can also tell the other person discretely that they should lock their screen before leaving the desk.

So to stop those wannabe-security-officers, I've created a simple script that you can leave running without locking your screen:


# People love to get their hands on someone else's pc while they
# go away and forget to lock their computer
# Activate this little script and then walk away, tricking the 
# ignorant and arrogant alike to think you forgot to lock your screen.
# Then, when they try to 'modify' your wallpaper/settings/etc. the
# script will detect the unauthorized access and put them on the
# wall of shame. That is, taking a picture using the webcam, 
# adding some text and then displaying it to them, before locking
# the computer.
# L.S. Keijser

# initial delay so we don't get shamed ourselves
sleep 5

# change to homedir
cd ~

# delete old shame files
rm -f 00000001.png wallpaper.png me

# start watching for intruders
while true ; do
    # this produces idle time in miliseconds
    # check if somebody is typing and/or using the mouse
    if [ $IDLETIME -lt 3500 ]; then
        # give owner a chance to kill the script
        sleep 3
        # extra bonus protection: check for a 'me' file in the homedir
        if [ -f ~/me ]; then
            # ah, it's the owner .. exit!
            exit 0
        # so, someone was actively using it? initiate shame-routine!
        # step 1: take picture
        mplayer -vo png -frames 1 tv:// 
        # step 2: add text
        convert -pointsize 30 -fill red -draw 'text 0,460 "WALL OF SHAME - do not mess with my laptop"' 00000001.png ~/shame.png
        # step 3: show user their mistake
        eog -f ~/shame.png &
        # step 4: let them know we know 
        sleep 5
        # step 5: set as lockscreen
        export $(cat /proc/$(pgrep -u `whoami` ^gnome-shell$)/environ | grep -z DBUS_SESSION_BUS_ADDRESS)
        DISPLAY=:0 GSETTINGS_BACKEND=dconf /usr/bin/gsettings set org.gnome.desktop.background picture-uri file://$HOME/shame.png
        DISPLAY=:0 GSETTINGS_BACKEND=dconf /usr/bin/gsettings set org.gnome.desktop.screensaver picture-options zoom 
        # step 6: activate lock screen
        dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock 
        # exit normally
        exit  0
    # wait a little bit before checking idle time
    sleep 1


It take s a little work because it requires the following tools to be installed on your distribution:

  • xprintidle
  • mplayer
  • imagemagick
  • a working webcam

The first one might not be available on your distribution. I know Fedora 22 and higher doesn't include it in any standard repository. I've found a copy of the source code here. Unfortunately it wouldn't compile on my laptop. When issuing ./configure , I got:


configure: error: libX11 not found


So after some googling, I managed to get it working. Here's a patch I made:


--- xprintidle-0.2/configure	2008-10-14 16:53:24.000000000 +0200
+++ xprintidle-0.2-modified/configure	2015-11-09 17:10:14.698582780 +0100
@@ -3977,7 +3977,7 @@
 # Checks for libraries.
-LIBS="$LIBS -L$x_libraries"
 { $as_echo "$as_me:$LINENO: checking for XOpenDisplay in -lX11" >&5
 $as_echo_n "checking for XOpenDisplay in -lX11... " >&6; }


To patch it, extract the xprintidle tar.gz and run:


~ $ cd xprintidle-0.2
xprintidle-0.2 $ patch -p1 < ../xprintidle.patch 
patching file configure


Then run ./configure && make && sudo make install.

Save the script in your homedir or something, and use it like this:

  • you run the script from a terminal
  • don't touch the keyboard or mouse anymore
  • leave your laptop unlocked
  • walk away from your desk

Now when someone sees your unlocked screen and tries something (that it, pressing a key or moving the mouse) the following happens:

  • a picture is being taken using your webcam
  • the picture is saved and modfied (text added) using imagemagick tool 'convert'
  • the resulting image is opened using Eye of GNOME (eog) and displayed to the person
  • the script waits a couple of seconds to let them view the image and text
  • image is set as the lockscreen image
  • screen is being locked