Lubuntu system sounds

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.

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?

Thanks

Carlos-Lubuntu

Hi cacaedu, welcome to the forum! :wave:

By any chance, do the AI generated instructions offered at the top of the page here help at all? They’re listed under the title “Lubuntu USB Sound Trigger.” :slightly_smiling_face:

Regards…

1 Like

Hello.

Unfortunately, no.

I tried other script too, but without success.

Thanks

Hi cacaedu! :wave:

Did you receive any error (or other) messages in the process of trying to get this to work? If so, could you post them? :slightly_smiling_face:

Regards…

Hello, @ardvark71 !

The udev group did not exist and I created it and associated it with my user. All permissions were set and more.

I think the problem is the system values ​​matching in the created .rules file. For example: SUBSYSTEM==“usb” ACTION==“add” etc. This may be incompatible.

See my conversation with Gemini below. I tried several scripts but to no avail.

Absolutely! 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:

  1. 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.

  2. 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/.
  1. 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

  1. 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.
  1. 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

  1. 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.

Note: Everything works fine when tested line by line of code, except when the USB is inserted. Then the sound is not triggered. Therefore, I think the problem is in the correspondence with the system data (ACTION, SUBSYSTEM…) so that the triggering occurs. Could you tell me what the possible problems are related to the triggering (insertion of the USB)?

Thanks

Hi cacaedu! :wave:

I’m sorry, I’m afraid I can’t help you with this aspect of your issue. What you’ve posted is definitely above my “pay grade,” so to speak. Perhaps someone else on the forum can help you with this. :slightly_smiling_face:

Regards…

No problem. You helped me with the link you posted.

Thanks for your time.