I'd like to lock the screen when I move my mouse to the bottom-right corner.

Is there a compiz-configuration for that task?

I could not find anything in the compizconfig-settings-manager and system settings.


The simple tools to get mouse position is xdotool just install first and follow steps:

sudo apt-get install xdotool

then we are useing xdotool getmouselocation --shell to see the current position of mouse: the result will be something like this:


or by running eval $(xdotool getmouselocation --shell) will put the position into shell variables X, Y and SCREEN. After that, we can access these variables with this:

echo $X $Y $SCREEN

Well now we need a while loop to check mouse position on every time:

while true
    [get mouse position]
    [if position =bottom-right corner then lock screen]

ok so our scripts would be like this:

#! /bin/sh
while true
    eval $(xdotool getmouselocation --shell)
    if [ $X -ge 1919 -a  $Y -ge 1079 ]; then
        gnome-screensaver-command -l

save script named "lock.sh" in your home directory and run it by sh lock.sh and move your mouse to the bottom-right corner and see the result. cool!


We combine conditions by using certain operators. For the single-bracket syntax that we’ve been using so far, “-a” used for and. and “-o” for or. Example:

if [ $foo -ge 3 -a $bar -ge 10 ]; then

The above condition will return true if $foo contains an integer g reater than or e qual to 3 (-ge 3) and also $bar contains an integer g reater than or e qual to 10. then run lock screen command line gnome-screensaver-command -l

  • 2
    Nice, +1, but I'd add a little sleep somewhere. It's spinning like a crazy... ;-) --- and probably I'd even check if the mouse is staying in the corner (this is for @JacobVlijm too), like checking two times in half a second, before locking. – Rmano Sep 2 '14 at 14:54

I could not find any settings in the Compiz manager, nor in the Unity Tweak settings (which uses the same), but if you add the script below to your Startup Applications, it will check your screen resolution and your mouse position. If the mouse is within a marge from the corner (set in the head of the script) it will lock the screen.

How to use

  1. Install xdotool:

    sudo apt-get install xdotool
  2. Paste the script below in an empty file, set the marge (pixels) within which you would like the hotcorner to act, save it as screenlock.py, make it executable for convenience reasons and add it to your startup applications (Dash > Startup Applications > Add). Add add the command:


The script:

#!/usr/bin/env python3

import time
import subprocess

marge = 3 # (pixels) increase to increase sensitivity

output = subprocess.check_output(["xrandr"]).decode('utf-8').strip().split()
idf = output.index("current")
res = (int(output[idf+1]), int(output[idf+3].replace(",", "")))

command = "gnome-screensaver-command -l"

while True:
    get_pos = subprocess.check_output(["xdotool", "getmouselocation", "--shell"]).decode('utf-8').strip().split("\n")
    pos = (int(get_pos[0][2:]), int(get_pos[1][2:]))
    if res[0] - pos[0] < marge and res[1] - pos[1] < marge:
        subprocess.Popen(["/bin/bash", "-c", command])
  • @Rmano Since the script sleeps a second before checking again, that is kind of "built in" already. – Jacob Vlijm Sep 2 '14 at 16:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.