41 lines
1.1 KiB
Plaintext
41 lines
1.1 KiB
Plaintext
|
#!/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 <j@cin.is>"
|
||
|
__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":"<span font='Font Awesome 5 Free Solid' color='#BE616E'>\uf1f6</span>"}
|
||
|
else:
|
||
|
RTN = {"full_text":"<span font='Font Awesome 5 Free Solid' color='#A4B98E'>\uf0f3</span>"}
|
||
|
|
||
|
print(json.dumps(RTN))
|