Question

The Ubuntu startup/login sound can be very loud, but I do like having it. I wrote a script that uses amixer to set the volume to 25%. This is the level I like to have it at, but when I use TV out or headphones I have to turn up the volume. I cannot seem to get the script to run before the login sound plays. I have tried a cron @reboot, and putting a symlink to the script in /etc/rc3.d/, and in my .bash_profile script. Only the 3rd method actually sets the volume correctly, but after the login sound plays.

Ideally I want to have the script run when I am logging out for the night, or just before the ubuntu login screen displays.

Here is the command to set the volume:

`/usr/bin/amixer -c 0 sset Master,0 25% > /dev/null`

Suggestions for other methods to try are appreciated.

Was it helpful?

Solution

You might want to try adding that line to your like to /etc/rc.local This may not be soon enough though, since rc.local will be called after gdm.

Also note, the default runlevel on Ubuntu is 2, not 3. Your link in rc3.d probably didn't work simply because you where not using runlevel 3. The default runlevel is setup by /etc/event.d/rc-default

OTHER TIPS

I believe that Ubuntu's startup scripts already include an "alsactl restore". You should be able to run "alsactl store" with the volume already set to 25% and affect all future reboots.

Ahh, yes, but do they also contain an "alsactl store" on shutdown?

Rob,

I am trying to solve the same issue. I took you "amixer" line above and did alot of poking around learning about runlevels, the /etc/rc#.d folders and the update-rc.d command. It's not perfect. It still doesn't run during a restart the way I would want it to, but its a start.

Suggestions to improve it would would be welcome.

And, here is my code below.....

sudo echo "#!/bin/bash" > /etc/init.d/lowvol.sh

sudo echo "/usr/bin/amixer -c 0 sset Master,0 35% > /dev/null" >> /etc/init.d/lowvol.sh

sudo chmod +x /etc/init.d/lowvol.sh

sudo chown root:root /etc/init.d/lowvol.sh

sudo update-rc.d lowvol.sh stop 20 0 6 .

I've used this method to achieve that before, but on Arch Linux. Now, I'm not too familiar with the init system Ubuntu uses, but I guess you could try adapting this to Ubuntu.

What you can do is to write a script to lower down your volume when you shut down your computer. Something like this:

#!/bin/sh

amixer -- sset Master playback -40dB

exit 1 

then run this script at shutdown.

Create a unit configuration and enable it for startup.

Assuming ALSA and systemd (Ubuntu uses systemd version after 14 onwards)

/etc/systemd/system/alsavolume.service

Create a unit file here. You can adjust the command to run /usr/bin/amixer sset PCM -- 97%. Remember not to use quotations (otherwise systemd will interpret the whole thing as a command).

[Unit]
Description="Set volume level."
After=sound.target

[Service]
Type=simple
ExecStart=/usr/bin/amixer sset PCM -- 97%

[Install]
WantedBy=multi-user.target

Enable it (this means creating a symbolic link to /etc/systemd/system/multi-user.target.wants to run at startup, but the following commands take care of it for you.)

  1. Reload daemons

    systemctl daemon-reload

  2. Enable service

    systemctl enable alsavolume.service

    You can add the parameter --now to run the unit immediately.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top