Akom's Tech Ruminations

Various tech outbursts - code and solutions to practical problems

Getting Pidgin to sign off when you lock your screen Linux

Posted by Admin • Wednesday, October 14. 2009 • Category: Linux

I am signed in to google talk from many places - blackberry, laptops, desktops, etc - and every once in a while, IM's don't go to the right one. Since I lock my workstation at the office whenever I get up, I figured it'd be nice to have Pidgin log off at the same time.

I am not sure how you would do this in Windows, but in Linux (Ubuntu in my case), I did it like this:

Changed my screen lock hotkey (Ctrl-Alt-l for me) to run the following:
xlock -startCmd "purple-remote setstatus?status=offline" -endCmd "purple-remote setstatus?status=available"
That's it. If you want specific screensaver modes you can stick them in them too:
xlock -mode blank -startCmd "purple-remote setstatus?status=offline" -endCmd "purple-remote setstatus?status=available"

Update: July 2012

Ubuntu has a broken version of xlock (1:5.31-1) which gets the BadMatch (invalid parameter attributes) error. I switched to using slock from "suckless-tools" package, like so:
bash -c "purple-remote setstatus?status=offline ; slock ; purple-remote setstatus?status=available"

Interestingly, after running slock, xlock works too.. it's actually related to dpms: If you run xset +dpms, xlock will work (once).
You can adjust the xlock version for this bug as follows:
xlock -mode blank -startCmd "xset +dpms ; purple-remote setstatus?status=offline" -endCmd "purple-remote setstatus?status=available"

PS: Doing this in openbox:

<keybind key="C-A-l">
        <action name="Execute">
                <command>xlock -startCmd "purple-remote setstatus?status=offline" -endCmd "purple-remote setstatus?status=available"</command>

0 Trackbacks

  1. No Trackbacks


Display comments as (Linear | Threaded)
  1. For me the commented solution didn't work so I decided to use the builtin "gnome-screensaver-command" and launch next bash script when Screen Lock:

    # Lock Screen + Pidgin On/Off
    bash -c "gnome-screensaver-command --lock"
    bash -c "purple-remote setstatus?status=offline"
    while [ "`gnome-screensaver-command --query | head -1`" = "The screensaver is active" ]; do
    # do nothing
    # Put here some commands to run after unlocking..
    bash -c "purple-remote setstatus?status=away"
  2. You might notice one your cores spiking when using this... except you won't since screensaver is on :-) .
    I'd recommend at least putting a "sleep 1" in your loop. Your script is busywaiting.
    Additionally, it may be risky to match for the exact string... I'd opt for " | head -1 | grep -i active > /dev/null "
  3. thanks for the advices!

Add Comment

You can use [geshi lang=lang_name [,ln={y|n}]][/geshi] tags to embed source code snippets.
Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.

What is the primary language of this blog? (Anti-SPAM question)

Submitted comments will be subject to moderation before being displayed.