Skip to content

Instantly share code, notes, and snippets.

@gbishop
Created January 6, 2011 19:17
Show Gist options
  • Save gbishop/768395 to your computer and use it in GitHub Desktop.
Save gbishop/768395 to your computer and use it in GitHub Desktop.
Mute Rhythmbox at the top of the hour so I don't hear the news break
#!/usr/bin/python
'''I run this with crontab using the line:
1 8-17 * * 1-5 /home/gb/bin/muteRadio
'''
import sys
import os
import time
import dbus
# set up the environement so I can access rhythmbox
os.environ['XAUTHORITY'] = '/home/gb/.Xauthority'
os.environ['DISPLAY'] = ':0.0'
# send messages where I can see them
sys.stdout = sys.stderr = file('/var/tmp/mute.log', 'a')
# access the player interface of Rhythmbox
bus = dbus.SessionBus()
proxy_obj = bus.get_object('org.gnome.Rhythmbox', '/org/gnome/Rhythmbox/Player')
player = dbus.Interface(proxy_obj, 'org.gnome.Rhythmbox.Player')
# test if I'm listening to the radio
if player.getPlayingUri() != 'http://152.9.6.199:1910/listen.pls':
print 'not radio'
sys.exit(0)
# remember the current volume
v = player.getVolume()
# mute the news
player.setVolume(0)
# wait for the news to end
time.sleep(5 * 60)
# restore the volume after the news
player.setVolume(v)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment