#!/usr/bin/env python import dbus, dbus.exceptions import sys import re try: bus = dbus.SessionBus() timetracker = bus.get_object('org.gnome.Shell', '/timepp/zagortenay333/TimeTracker') except dbus.exceptions.DBusException as e: print('D-Bus error: {}'.format(str(e))) sys.exit(2) tracked_tasks = timetracker.get_dbus_method('get_tracked_tasks', 'timepp.zagortenay333.TimeTracker')() tracked_tasks = tracked_tasks.split('___timepp___') ## get the first tracked task (if we might track multiple tasks) tracked_task = tracked_tasks[0] ## remove any priority, optional dates etc from the beginning of the task tracked_task = re.sub(r'^(\([A-Z]\))?[ ]*([0-9]{4}-[0-9]{2}-[0-9]{2})?[ ]*', '', tracked_task) ## get the first word (hopefully Jira ticket ID reference) tracked_task = tracked_task.split(' ')[0] ## highlight if tracker running print(tracked_task + (' | color="#f47e00"' if tracked_task != 'none' else ''))