Skip to content

Commit

Permalink
✨ do-not-disturb: add DND utility
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianmiranda committed Jan 18, 2024
1 parent 60896d1 commit a6f7078
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 11 deletions.
6 changes: 3 additions & 3 deletions home/.config/polybar/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -444,11 +444,11 @@ click-right = alacritty --class i3FloatingWindow -e $HOME/bin/vpn --disconnect

[module/dunst]
type = custom/script
interval = 2
interval = 1
format = <label>
label = "%output%"
exec = .config/polybar/scripts/dunstctl
click-left = .config/polybar/scripts/dunstctl --toggle
exec = .config/polybar/scripts/do-not-disturb
click-left = .config/polybar/scripts/do-not-disturb --toggle

[module/spotify]
type = custom/script
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ case "$1" in
--toggle)
muted=$(dunstctl is-paused 2>/dev/null)
if [[ $muted == "true" ]]; then
dunstctl set-paused false 2>/dev/null
$HOME/bin/do-not-disturb off
else
dunstctl set-paused true 2>/dev/null
$HOME/bin/do-not-disturb on
fi
;;
*)
Expand Down
20 changes: 20 additions & 0 deletions home/bin/do-not-disturb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

MODE=$1 # on/off

APPS=(
"telegram-desktop"
"whatsapp-for-linux"
)

if [ "$MODE" == "on" ]; then
MODE="mute"
dunstctl set-paused true 2>/dev/null
else
MODE="unmute"
dunstctl set-paused false 2>/dev/null
fi

for APP in "${APPS[@]}"; do
$HOME/bin/toggle-app-audio $APP $MODE
done
12 changes: 6 additions & 6 deletions home/bin/lock-screen
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ XIDLEHOOK_LOCK_SOCKET=/tmp/xidlehook.sock

NO_FORK="--nofork"

function pauseNotifications() {
dunstctl set-paused true
function doNotDisturbOn() {
$HOME/bin/do-not-disturb on
}

function resumeNotifications() {
dunstctl set-paused false
function doNotDisturbOff() {
$HOME/bin/do-not-disturb off
}

function turnScreenOff() {
Expand Down Expand Up @@ -82,15 +82,15 @@ function lockScreen() {
if pgrep -x "i3lock" >/dev/null; then
echo "Computer already locked. Aborting..."
else
pauseNotifications
doNotDisturbOn
muteVolume
turnScreenOff

openrgb --mode static --color 000000
runLocker
openrgb --mode static --color 0313fc

resumeNotifications
doNotDisturbOff
unmuteVolume
fi
}
Expand Down
14 changes: 14 additions & 0 deletions home/bin/toggle-app-audio
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

APP_NAME=$1
ACTION=$2
SINK_INPUTS=$(pactl list sink-inputs | grep -i -E -B 20 "(application.name = \"$APP_NAME\"|device.description = \"$APP_NAME\")" | grep "Sink Input #" | awk '{print $3}' | sed 's/#//g')

for SINK in $SINK_INPUTS; do
MUTE_STATUS=0
if [ "$ACTION" == "mute" ]; then
MUTE_STATUS=1
fi

pactl set-sink-input-mute $SINK $MUTE_STATUS
done

0 comments on commit a6f7078

Please sign in to comment.