Is there a way to toggle Do Not Disturb from the commandline?
Is there a command or flag we can pass to enable or disable do not disturb? Right now the only way I know of is through clicking on the date and time and then the toggle button. This would help in making a keyboard shortcut to toggle it when needed.
42 Answers
Thanks to @UnKNOWn, I found this command and with a little tweaking, I was able to create a script to toggle Do Not Disturb mode. Here is the GitHub repo to the script. I set a keyboard shortcut in the settings to make it usable.
Edit: For anyone not wanting to deal with a script, you can simply use Super + V to open up the notifications menu and press space to toggle DND. Realized this the day after, but I hope the script helps haha.
3You can also do this through Python as well. Using something like systemd/supervisord/etc, this can be done automatically:
import subprocess
import time
# Time to set when dnd should start/stop
dnd_time = {'start': {'hour': 17, 'minute': 00}, 'end': {'hour': 8, 'minute': 00}}
sleep_time = 30
def get_dnd_status(): enabled = None # get to check 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 to apply 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) 3