How to have a specific set audio volume on booting or logging in to Plasma5 desktop

This How To is specific to Plasma Desktop and will not work on other desktops. It probably could be adapted by putting the file in the correct directory.

Full credit where it is due: I actually got this from @abucodonosor aka: crazy on #openmandriva-cooker @ Freenode IRC.

Basically a simple script that resets volume setting upon logout, reboot, or shutdown. Thus this will be the volume every time you login. This works in Plasma5 desktop. I have not yet tested in other desktops.

Using any text editor create the file ‘~/.config/plasma-workspace/shutdown/pa.sh’. I’m using the editor ‘nano’ in this example you can use vi or whatever you are familiar with.

$ cd ~/.config/plasma-workspace/shutdown

$ nano pa.sh

and in nano insert:

#!/bin/bash

pactl set-sink-volume 0 20%

write the file with CTL+o then ENTER and close nano with CTL+x. Then make the file executable:

$ chmod +x pa.sh

Set volume to 100% and logout or reboot to test. Obviously you can use any value you wish in place of 20%.

Next I’ll show how to do this with a cool GUI that lets you select volume when you logout or reboot/shutdown.

1 Like

To create an interactive GUI that will ask you to set volume every time you reboot, or shutdown create the file ‘~/.config/plasma-workspace/shutdown/pa.sh’ as above but instead include this in the file:

#!/bin/bash


pa_foo_bar() {

    local pa_cmd=$(type -P pactl)
    local k_cmd=$(type -P kdialog)

    if [ -e "$pa_cmd" -a -e "$k_cmd" ]; then

        pa_volume=$(kdialog --combobox "Choose pulseaudio volume level:" "10" "20" "30"  --default "20");

        if [ "$?" = 0 ]; then
            if [ "$pa_volume" = "10" ]; then
                pactl set-sink-volume 0 10%
            elif [ "$pa_volume" = "20" ]; then
                pactl set-sink-volume 0 20%
            elif [ "$pa_volume" =  "30" ]; then
                pactl set-sink-volume 0 30%
            else
                ## not possible but is kdialog :D
                pactl set-sink-volume 0 20%
            fi
        fi
    fi
}


pa_foo_bar

Don’t forget to make the file executable:

$ chmod +x ~/.config/plasma-workspace/shutdown/pa.sh

Now whenever you logout, reboot, or shutdown you will be presented with a dialog window asking you to set the audio volume. Again you can change the values to suit your own wishes. This works in Plasma5 desktop. I have not yet tested in other desktops.