Created
November 3, 2019 17:32
-
-
Save pfrenssen/d573e100a27432d1fe824846186ede4c to your computer and use it in GitHub Desktop.
Notify workrave timers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /home/pieter/.config/systemd/user/workrave-notification.service | |
[Unit] | |
Description=Show a notification with the remaining Workrave time | |
[Service] | |
ExecStart=python /home/pieter/v/python/workrave-timer.py | |
[Install] | |
WantedBy=multi-user.target | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.config/systemd/user/workrave-notification.timer | |
[Unit] | |
Description=Show notification with Workrave timers every minute | |
[Timer] | |
OnCalendar=*:*:0 | |
Persistent=true | |
[Install] | |
WantedBy=timers.target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pydbus import SessionBus | |
from datetime import timedelta | |
import psutil | |
# Only notify if the user is logged in. | |
user_logged_in = False | |
for user in psutil.users(): | |
if user.name == 'pieter': | |
user_logged_in = True | |
break | |
if not user_logged_in: | |
exit(0) | |
# Only notify if workrave is running. | |
workrave_running = False | |
for proc in psutil.process_iter(attrs=['name']): | |
if proc.info['name'] == 'workrave': | |
workrave_running = True | |
break | |
if not workrave_running: | |
exit(0) | |
bus = SessionBus() | |
# For documentation on the DBus interface for Workrave, see | |
# https://github.com/rcaelers/workrave/blob/branch_v1_10/backend/src/workrave-service.xml | |
workrave = bus.get('org.workrave.Workrave', '/org/workrave/Workrave/Core') | |
microbreak_remaining = timedelta(seconds=workrave.GetTimerRemaining('microbreak')) | |
restbreak_remaining = timedelta(seconds=workrave.GetTimerRemaining('restbreak')) | |
# Show a notification with the current remaining time. | |
notifications = bus.get('.Notifications') | |
notification = 'Rest: ' + str(restbreak_remaining) + "\nMicro: " + str(microbreak_remaining) | |
notifications.Notify('workrave-timer', 0, 'dialog-information', 'Workrave', notification, [], {}, 20000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment