feat: random notification sounds
This commit is contained in:
33
swaync/scripts/sound.sh
Executable file
33
swaync/scripts/sound.sh
Executable 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"
|
||||
}
|
||||
Reference in New Issue
Block a user