[quote=“cacaedu, post:1, topic:5299, full:true”]
Hello everyone!
I’m using Lubuntu to test on an old machine.
I can’t hear any sound when some event happens (notification, USB insertion, etc.).
The sounds (Ogg Vorbis audio files) exist in /usr/share/sounds/freedesktop/stereo, but they are not linked to any event - at least that’s what it seems.
How can I link these audio files to events like notification, USB insertion or system shutdown, for example?
Do I have to write any script?
I asked Gemini and received the following response:
"Here’s how you can create a script to play a sound when a USB device is inserted in Lubuntu, along with explanations to help you understand the process:
Create the Sound File
Choose a sound: Select a short, distinct sound file (e.g., a “ding” or a notification chime). You can find free sound effects online.
Save the sound: Save the sound file in a location where it won’t be accidentally deleted. A good place would be a dedicated folder in your home directory, like ~/sounds/usb_insert.wav.
Create the Script
Open a text editor: Use a text editor like nano or mousepad to create a new file. Let’s name it usb_sound.sh.
Paste the code: Copy and paste the following code into the file:
Bash
#!/bin/bash
Play the sound file
aplay ~/sounds/usb_insert.wav &
Optional: Display a notification
notify-send “USB Device Inserted” “A sound has been played.”
Explanation:
#!/bin/bash: This line tells the system to use Bash to execute the script.
aplay ~/sounds/usb_insert.wav &: This line plays the sound file using the aplay command. The & symbol runs the command in the background so it doesn’t block other actions.
notify-send “USB Device Inserted” “A sound has been played.”: This line is optional. It displays a notification on your screen when the USB is inserted.
Save the file: Save the usb_sound.sh file in a convenient location, such as ~/scripts/.
Make the Script Executable
Open a terminal: Open the Lubuntu terminal.
Navigate to the directory: Use the cd command to navigate to the directory where you saved the script (e.g., cd ~/scripts).
Make it executable: Use the following command to make the script executable:
Bash
chmod +x usb_sound.sh
Configure udev Rules
Create a udev rule file: Open a text editor as administrator (you might need to use sudo) and create a new file named 99-usb-sound.rules in the /etc/udev/rules.d/ directory.
Paste the rule: Copy and paste the following rule into the file:
SUBSYSTEM==“usb”, ACTION==“add”, ENV{UDISKS_PRESENT}!=“1”, RUN+=“/home/yourusername/scripts/usb_sound.sh”
Explanation:
SUBSYSTEM==“usb”: This matches events related to USB devices.
ACTION==“add”: This matches the event of a USB device being added.
ENV{UDISKS_PRESENT}!=“1”: This condition is optional. It prevents the sound from playing if the USB device is a storage device that’s automatically mounted by udisks.
RUN+=“/home/yourusername/scripts/usb_sound.sh”: This specifies the script to run when the rule is matched. Important: Replace /home/yourusername/scripts/usb_sound.sh with the actual path to your script.
Save the file: Save the 99-usb-sound.rules file.
Reload udev Rules
Open a terminal: Open the Lubuntu terminal.
Reload the rules: Use the following command to reload the udev rules:
Bash
sudo udevadm control --reload-rules
Test the Script
Insert a USB device: Insert a USB device into your computer.
Listen for the sound: You should hear the sound file playing. If you included the notification, you should also see it on your screen.
Troubleshooting
Sound not playing:
Double-check the path to the sound file in the script.
Make sure the sound file is in a format that aplay supports (e.g., WAV).
Check the volume level.
Script not executing:
Make sure the script is executable (chmod +x).
Double-check the path to the script in the udev rule.
Check the udev logs for any errors (sudo udevadm monitor --udev).
Let me know if you have any other question."
I did all this and it didn’t work.
Thanks
Carlos-Lubuntu