feat: random notification sounds

This commit is contained in:
2025-12-25 02:10:43 +03:00
parent deace16b64
commit b453f9efd7
4 changed files with 36 additions and 8 deletions

View File

@@ -33,14 +33,9 @@
"text-empty": "No nothing",
"script-fail-notify": true,
"scripts": {
"example-script": {
"exec": "echo 'Do something...'",
"urgency": "Normal"
},
"example-action-script": {
"exec": "echo 'Do something actionable!'",
"urgency": "Normal",
"run-on": "action"
"notification-sound": {
"exec": "sh $HOME/.config/swaync/scripts/sound.sh",
"app-name": "^(?!.*AyuGram).*$"
}
},
"notification-visibility": {

33
swaync/scripts/sound.sh Executable file
View File

@@ -0,0 +1,33 @@
#!/bin/bash
if [ $(swaync-client --get-dnd) == "true" ]; then
echo "Do Not Disturb is on, skipping sound"
exit 0
fi
# Directory containing your notification sounds
SOUND_DIR="$HOME/.config/swaync/scripts/sounds"
# Enable nullglob to prevent literal interpretation when no files match
shopt -s nullglob
# Get a list of audio files in the directory (simpler approach)
SOUND_FILES=()
for ext in wav mp3 ogg flac; do
SOUND_FILES+=("$SOUND_DIR"/*."$ext")
done
# Check if any sound files exist
if [ ${#SOUND_FILES[@]} -eq 0 ]; then
echo "No sound files found in $SOUND_DIR"
exit 0 # Exit with success so notifications still work
fi
# Select a random sound file
RANDOM_INDEX=$((RANDOM % ${#SOUND_FILES[@]}))
RANDOM_SOUND="${SOUND_FILES[$RANDOM_INDEX]}"
# Play the random sound
play -v 0.5 "$RANDOM_SOUND" 2>/dev/null || {
echo "Failed to play $RANDOM_SOUND"
}

Binary file not shown.

Binary file not shown.