Pause torrents while I’m using the computer

I use the Transmission BitTorrent client, and it’s pretty cool. However, it’s irritating when it eats my bandwidth while I’m trying to do stuff. So, one obvious hack would be to disable it when the screensaver is off (i.e., I’m using the computer) and enable it only when the screensaver is on (i.e., I’m in bed). Fortunately, Transmission has an API (which you have to enable by turning on the web interface in Preferences) and you can watch the Gnome screensaver for changes. So, a quick Python script later, and throw that Python script and Transmission itself into your session Startup Programs to make them run whenever you log in, and Bob’s your uncle. the script:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/env python
import dbus, urllib
from dbus.mainloop.glib import DBusGMainLoop

START_TORRENTS = "http://localhost:9091/transmission/rpc?method=torrent-start"
STOP_TORRENTS = "http://localhost:9091/transmission/rpc?method=torrent-stop"

DBusGMainLoop(set_as_default=True)
sess=dbus.SessionBus()
def sig(screensaverActive):
  if screensaverActive:
    data = urllib.urlopen(START_TORRENTS).read()
  else:
    data = urllib.urlopen(STOP_TORRENTS).read()

sess.add_signal_receiver(sig, 'ActiveChanged','org.gnome.ScreenSaver')
import gobject
loop = gobject.MainLoop()
loop.run()

More in the discussion (powered by webmentions)

  • (no mentions, yet.)