You are not logged in.

#1 2010-03-17 13:35:05

kamahl
Member
Registered: 2007-09-16
Posts: 60

Fn+F2 to lock screen on Lenovo ThinkPad

Hi, I just wanted to post here instructions how to make Fn+F2 key shortcut to lock screen properly on Lenovo ThinkPad (tested on x200s), because it took me quite a lot of time finding out how to do it. I wanted it to lock all sessions on all virtual displays, which makes it a little more complicated.

1) make sure your acpid and dbus work

2) Create a file named /etc/acpi/events/fn-f2.sh with the following content:

event=ibm/hotkey HKEY 00000080 00001002
action=/etc/acpi/dbus-lock-screen.sh %e

3) Create a file named /etc/acpi/dbus-lock-screen.sh with the following content:

#!/bin/bash
users=$(who|grep '^\w\w* *:'|awk '{print $1}'|sort|uniq)
for user in $users; do
        userhome=$(grep "^$user:" /etc/passwd|awk -F : '{print $6}')
        cd "$userhome/.dbus/session-bus/"
        for sf in $(ls); do
                source $sf
                export DBUS_SESSION_BUS_ADDRESS
                export DBUS_SESSION_BUS_PID
                export DBUS_SESSION_BUS_WINDOWID

                su $user -c 'qdbus org.freedesktop.ScreenSaver /ScreenSaver Lock' 
        done
done

4) chmod +x /etc/acpi/dbus-lock-screen.sh
5) /etc/rc.d/acpid restart

Thats it, now pressing Fn+F2 will lock all X sessions,

Offline

#2 2010-03-22 19:02:50

demian
Member
From: Frankfurt, Germany
Registered: 2009-05-06
Posts: 709

Re: Fn+F2 to lock screen on Lenovo ThinkPad

Thanks for sharing.
Doesn't work for me on X200s though.
Sadly, I don't really have the time to dive into the topic to find out what's wrong.

Regards,
demian

Last edited by demian (2011-04-30 15:00:45)


no place like /home
github

Offline

#3 2010-03-26 00:32:02

qubit
Member
Registered: 2007-04-25
Posts: 47

Re: Fn+F2 to lock screen on Lenovo ThinkPad

Problem is in regex for grep in $users - it returns nothing for me. Simple grep '(:'
should work.
Because I'm the only user on my laptop, this works for me

su -c ". ~/.dbus/session-bus/$(cat /var/lib/dbus/machine-id)-0 ;
export DBUS_SESSION_BUS_ADDRESS ;
/usr/bin/qdbus org.freedesktop.ScreenSaver /ScreenSaver Lock" \
- $user

Note that probably you need to change $(cat /var/lib/dbus/machine-id)-0 if your $DISPLAY is not :0.0

Offline

Board footer

Powered by FluxBB