Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

When I lock screen on Ubuntu, I want transmission to open up automatically, and when I unlock the screen, transmission should pause itself or die.

I have searched a lot but cannot find anything worthwhile.

I thought of a solution, of creating a cron job and using gnome-screensaver-command -q and starting up transmission, seems like a wastage. Is there a better way (something event based)?

share|improve this question
add comment

2 Answers

You can use dbus to get hold of the events when the screensaver activates or deactivates, see here.

You can use transmission-remote to control transmission from the command line, as shown here.

Therefore you will end up with a perl script along the lines of:

my $cmd = "dbus-monitor --session \"type='signal',interface='org.gnome.ScreenSaver',member='ActiveChanged'\"";

$starttrans="transmission-remote --torrent all --start";
$stoptrans="transmission-remote --torrent all --stop";

open (IN, "$cmd |");

while (<IN>) {
    if (m/^\s+boolean true/) {
        starttrans;
    } elsif (m/^\s+boolean false/) {
        stoptrans;
    }
}

(I'm writing this in Windows with no perl/ transmission so it is almost certainly not going to work properly.)

share|improve this answer
    
thanks for pointing in the right direction, but i don't know perl so cant check it right now. And, this for "member='SessionIdleChanged'". I want when I lock the screen manually. –  N 1.1 Oct 17 '10 at 10:40
add comment

Ok. I have come up with a python script which does what I want using dbus-monitor

#!/usr/bin/python
import os, sys

while True:
    line = sys.stdin.readline()
    if "boolean true" in line:
        print os.system("transmission -m &")
    elif "boolean false" in line:
        print os.system("pkill transmission")

On the shell,

dbus-monitor type=signal,\
             interface=org.gnome.ScreenSaver,\
             member=ActiveChanged\
             | ./script.py  &
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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