#!/usr/bin/env python3 """ A do-not-disturb button for muting Dunst notifications in i3 using i3blocks Mute is handled using the `dunstctl` command. """ __author__ = "Jessey White-Cinis " __copyright__ = "Copyright (c) 2019 Jessey White-Cinis" __license__ = "MIT" __version__ = "1.1.0" import os import subprocess as sp import json def mute_toggle(): '''Toggle dunst notifications''' sp.run(["dunstctl", "set-paused", "toggle"], check=True) def clicked(): '''Returns True if the button was clicked''' button = os.environ.get("BLOCK_BUTTON", None) return bool(button) def muted(): '''Returns True if Dunst is muted''' output = sp.check_output(('dunstctl', 'is-paused')) return u'true' == output.strip().decode("UTF-8") if clicked(): # toggle button click to turn mute on and off mute_toggle() if muted(): RTN = {"full_text":"\uf1f6"} else: RTN = {"full_text":"\uf0f3"} print(json.dumps(RTN))