Skip to content

Instantly share code, notes, and snippets.

@Programazing
Created November 5, 2024 19:38
Show Gist options
  • Save Programazing/29d2959cd9365d4fe7fe1b2c89ee8a78 to your computer and use it in GitHub Desktop.
Save Programazing/29d2959cd9365d4fe7fe1b2c89ee8a78 to your computer and use it in GitHub Desktop.
A handy way to toggle Do Not Disturb in Gnome
#!/bin/bash
# Get the current Do Not Disturb status
current_status=$(gsettings get org.gnome.desktop.notifications show-banners)
# Toggle the status
if [ "$current_status" = "true" ]; then
gsettings set org.gnome.desktop.notifications show-banners false
echo "Do Not Disturb mode activated"
else
gsettings set org.gnome.desktop.notifications show-banners true
echo "Do Not Disturb mode deactivated"
fi
# Make the script executable with the command:
# chmod +x toggle_dnd.sh
# Run the script to toggle Do Not Disturb mode:
# ./toggle_dnd.sh
# Want this to be an alias? No problem!
# Open your shell configuration file (usually ~/.bashrc for Bash or ~/.zshrc for Zsh) in a text editor.
# Add the following alias definition to the file:
# alias toggle_dnd='current_status=$(gsettings get org.gnome.desktop.notifications show-banners); if [ "$current_status" = "true" ]; then gsettings set org.gnome.desktop.notifications show-banners false && echo "Do Not Disturb mode activated"; else gsettings set org.gnome.desktop.notifications show-banners true && echo "Do Not Disturb mode deactivated"; fi'
# Save the file and close your text editor.
# To apply the changes immediately, source your shell configuration file:
# source ~/.bashrc # If you're using Bash
# or
# source ~/.zshrc # If you're using Zsh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment