Skip to content

Instantly share code, notes, and snippets.

@Lvl4Sword
Last active August 27, 2021 07:29
Show Gist options
  • Save Lvl4Sword/6f3e094d3f14841e9a4a77b45aed45ec to your computer and use it in GitHub Desktop.
Save Lvl4Sword/6f3e094d3f14841e9a4a77b45aed45ec to your computer and use it in GitHub Desktop.
Programmatically enable DND mode on Ubuntu 20.04 LTS between 5PM - 8AM
import subprocess
import time
dnd_time = {'start': {'hour': 17, 'minute': 00}, 'end': {'hour': 8, 'minute': 00}}
sleep_time = 30
def get_dnd_status():
enabled = None
status = subprocess.check_output(['gsettings', 'get', 'org.gnome.desktop.notifications', 'show-banners']).strip().decode()
# 'false' means DND is enabled
if status == 'false':
enabled = True
else:
enabled = False
return enabled
def set_dnd_status(to):
set_it = subprocess.check_output(['gsettings', 'set', 'org.gnome.desktop.notifications', 'show-banners', f'{to}'])
if __name__ == '__main__':
current_time = time.localtime()
if dnd_time['start']['hour'] >= current_time.tm_hour >= dnd_time['end']['hour']:
set_dnd_status('true')
else:
enabled = get_dnd_status()
if enabled:
set_dnd_status('false')
time.sleep(sleep_time)
@Lvl4Sword
Copy link
Author

Minutes aren't actually paid attention to, but are easy enough to add.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment