View Single Post
Posts: 277 | Thanked: 319 times | Joined on Jan 2010
#900
Here's one:

I thought I'd test the dbus API and wrote a little python script to print out the current active rule(s). This can be used with Billboard, for example. One probably has to install python and python-dbus (apt-get install python python-dbus) to use this. Also, I'm almost a total newbie at python or scripting in general, so don't laugh too hard.

Code:
#----------------------------------------------------------------
# Name:        active_rule_names.py
# Purpose:     Print active profilematic rules except default rule
#
# Author:      Slarti
#
# Created:     26.11.2012
#----------------------------------------------------------------

import dbus
bus = dbus.SessionBus()
rule_obj = bus.get_object('org.ajalkane.profilematic', '/org/ajalkane/profilematic')
rule_intf = dbus.Interface(rule_obj, 'org.ajalkane.profilematic')
active_rule_ids = rule_intf.getMatchingRuleIds()
rule_names = rule_intf.getRuleNames()
lookup = []

for rule_name in rule_names:
    rule_id = rule_intf.getRuleIdForName(rule_name)
    lookup.append([rule_id, rule_name])

lookup_dict = dict(lookup)

for active_rule_id in active_rule_ids:
    active_rule_name = lookup_dict[active_rule_id]
    if active_rule_name == 'Default rule':
    	continue
    print active_rule_name.encode('utf-8')
Edit:

Fixed encoding to latin 1

Edit #2:

Changed to UTF-8 since Billboard 1.0.7 is out

Last edited by slarti; 2012-12-21 at 06:45.
 

The Following 5 Users Say Thank You to slarti For This Useful Post: