irongit
hygoland/scripts/Sounds.sh
77 lines2.3 KBBourne Again Shell (bash)
1#!/bin/bash
2# /* ---- 💫 https://github.com/JaKooLit 💫 ---- */ ##
3# This script is used to play system sounds.
4# Script is used by Volume.Sh and ScreenShots.sh
5
6theme="freedesktop" # Set the theme for the system sounds.
7mute=false # Set to true to mute the system sounds.
8
9# Mute individual sounds here.
10muteScreenshots=false
11muteVolume=false
12
13# Exit if the system sounds are muted.
14if [[ "$mute" = true ]]; then
15 exit 0
16fi
17
18# Choose the sound to play.
19if [[ "$1" == "--screenshot" ]]; then
20 if [[ "$muteScreenshots" = true ]]; then
21 exit 0
22 fi
23 soundoption="screen-capture.*"
24elif [[ "$1" == "--volume" ]]; then
25 if [[ "$muteVolume" = true ]]; then
26 exit 0
27 fi
28 soundoption="audio-volume-change.*"
29elif [[ "$1" == "--error" ]]; then
30 if [[ "$muteScreenshots" = true ]]; then
31 exit 0
32 fi
33 soundoption="dialog-error.*"
34else
35 echo -e "Available sounds: --screenshot, --volume, --error"
36 exit 0
37fi
38
39# Set the directory defaults for system sounds.
40if [ -d "/run/current-system/sw/share/sounds" ]; then
41 systemDIR="/run/current-system/sw/share/sounds" # NixOS
42else
43 systemDIR="/usr/share/sounds"
44fi
45userDIR="$HOME/.local/share/sounds"
46defaultTheme="freedesktop"
47
48# Prefer the user's theme, but use the system's if it doesn't exist.
49sDIR="$systemDIR/$defaultTheme"
50if [ -d "$userDIR/$theme" ]; then
51 sDIR="$userDIR/$theme"
52elif [ -d "$systemDIR/$theme" ]; then
53 sDIR="$systemDIR/$theme"
54fi
55
56# Get the theme that it inherits.
57iTheme=$(cat "$sDIR/index.theme" | grep -i "inherits" | cut -d "=" -f 2)
58iDIR="$sDIR/../$iTheme"
59
60# Find the sound file and play it.
61sound_file=$(find -L $sDIR/stereo -name "$soundoption" -print -quit)
62if ! test -f "$sound_file"; then
63 sound_file=$(find -L $iDIR/stereo -name "$soundoption" -print -quit)
64 if ! test -f "$sound_file"; then
65 sound_file=$(find -L $userDIR/$defaultTheme/stereo -name "$soundoption" -print -quit)
66 if ! test -f "$sound_file"; then
67 sound_file=$(find -L $systemDIR/$defaultTheme/stereo -name "$soundoption" -print -quit)
68 if ! test -f "$sound_file"; then
69 echo "Error: Sound file not found."
70 exit 1
71 fi
72 fi
73 fi
74fi
75
76# pipewire priority, fallback pulseaudio
77pw-play "$sound_file" || pa-play "$sound_file"