A collection of my scripts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

58 lines
1.6 KiB

#!/bin/sh
TIMESTAMP_FILE=~/.cache/notifications-disabler
notifications_are_disabled() {
dunstctl is-paused
}
send_notification() {
notify-send --urgency "$1" "$2" "$3"
}
remove_notification() {
dunstctl close
dunstctl debug
}
get_timestamp() {
date +%s
}
disable_notifications() {
dunstctl set-paused true
}
enable_notifications() {
dunstctl set-paused false
}
# If the meet isn't named, then the format is Meet - xxx-xxxx-xxx (x is a random letter)
# but if the meet is named, the name is displayed instead of the meet code.
if xwininfo -tree -root | grep -P '"Meet [-–] (\w{3}-\w{4}-\w{3}|.+) [-–] Chromium"' >/dev/null
then
if [ "$(notifications_are_disabled)" = "true" ]
then
current_timestamp=$(get_timestamp)
old_timestamp=$(cat "$TIMESTAMP_FILE")
if [ "$current_timestamp" -gt $(("$old_timestamp" + 3600)) ]
then
enable_notifications
send_notification "low" "Notifications paused" "Notifications are paused for longer than an hour. Did you forget to close the tab?"
sleep 5
remove_notification
disable_notifications
echo "$current_timestamp" > "$TIMESTAMP_FILE"
fi
else
send_notification "critical" "Meet detected" "Disabling notifications"
sleep 5
disable_notifications
get_timestamp > "$TIMESTAMP_FILE"
fi
else
if [ "$(notifications_are_disabled)" = "true" ]
then
enable_notifications
send_notification "critical" "Meet no longer detected" "Enabling notifications"
rm "$TIMESTAMP_FILE"
fi
fi