by davecs 13th July 2024, 6:23 pm
YES! This all works! I have system sounds!
I've got a couple of my own scripts for you, which you might want to try.
This one I've called xfce4-set-sound-theme and I've put it in /usr/local/bin/ . It enables a user to select a sound theme from inside the XFCE settings manager, from a drop-down menu. It will look in /usr/share/sounds/ and ~/.local/share/sounds/ for suitable sound layouts.
- Code:
#!/bin/bash
#We need to create a list of soundfile directories with an "index.theme" file.
#start up a file with the names, plus the option "None"
echo -n "None" > /tmp/soundlist.txt
#look in the system sounds theme area.
cd /usr/share/sounds
for g in *; do
if [ -d ${g} ]; then
cd $g
#folders without an "index.theme" file are ignored.
if [ -f "index.theme" ]; then
#the following line is to extract the sound name from index.theme. I found this didn't work,
#and that the actual folder name was preferred by XFCE4. It must not contain spaces.
# echo -n "!"$( cat index.theme | grep Name= | cut -c 6- ) >> ~/tmp/soundlist.txt
#just list by folder names.
echo -n "!""${g}" >> /tmp/soundlist.txt
fi
cd ..
fi
done
#look for sounds in user sounds theme area. First check that folder exists
xyz=~/.local/share/sounds
if [ -d $xyz ] ; then
cd $xyz
for g in *; do
if [ -d ${g} ]; then
cd $g
if [ -f "index.theme" ]; then
echo -n "!""${g}" >> /tmp/soundlist.txt
fi
cd ..
fi
done
fi
#we now have a list of entries for yad, with None, then system sounds in order,
#then local sounds in order. Make sure that all sounds have different names! We
#will pass text to XFCE4, and it will just use the first match it finds.
soundset=$(echo `cat ~/tmp/soundlist.txt`)
abc=`yad --width=450 --title="Select System Sounds" \
--image="/usr/share/icons/sound_section.png" \
--text="Current Sound Theme is: $( xfconf-query -c xsettings -p /Net/SoundThemeName )" \
--form --item-separator="!" \
--field="Select New Theme":CBE \
"$soundset" `
#test for "cancel"...
if [ "$abc" != "" ] ; then
#yad returns a string with an extra "|" at the end, so we have to remove it.
chosensound=$(echo -n "$abc" | rev | cut -c 2- | rev )
#Turn sounds off if "None" selected
if [ "$chosensound" == "None" ] ; then
xfconf-query -c xsettings -p /Net/EnableEventSounds -s false
xfconf-query -c xsettings -p /Net/EnableInputFeedbackSounds -s false
else
#Turn sounds on if one selected
xfconf-query -c xsettings -p /Net/EnableEventSounds -s true
xfconf-query -c xsettings -p /Net/EnableInputFeedbackSounds -s true
fi
#Set your chosen sound. I have used the command that forces a new Property to be created
#if there's not one already.
xfconf-query -c xsettings -p /Net/SoundThemeName -n -t string -s "$chosensound"
fi
And the following file, placed in /usr/share/applications is the one that puts it in the XFCE Settings Manager:
I've used the "click-radio" icon here though you might want to use a different one.
- Code:
[Desktop Entry]
Name=Sound Theme
Comment=Select a new Sound Theme
Exec=xfce4-set-sound-theme
Icon=click-radio
Terminal=false
Type=Application
Categories=XFCE;GTK;Settings;DesktopSettings;X-XFCE-SettingsDialog;X-XFCE-PersonalSettings;X-XFCE;X-Xfce-Toplevel;
OnlyShowIn=XFCE;
GenericName=Sound Theme Selector
The category line illustrates how to add any app to the XFCE settings manager.
As you can see, I'm not great at writing scripts, but this does get the job done.