It has happened to me that while people were sleeping in the early hours of the morning, I listened to heavy music at full volume and by mistake I disconnected the headphones which caused it to be played throughout the house (I think they hated me at that time haha). So program a little script that when disconnected, mutes the volume:
The first thing was to install alsa-utils to be able to manage the volume from commands easily:
sudo pacman -S alsa-utils
The next thing was to discover through a Google search that it alsa saves in plain text files (it can be read with any text editor, in Windows all this would be much more complicated) the status of the sound cards and that it only takes copy the file and then compare the changes.
The file is:
/proc/asound/card0/codec#0
This may vary in some cases, for example if we have more than one sound card. If you want to know more I leave the link of the alsa documentation: http://alsa.opensrc.org/Proc_asound_documentation
I connect the headphones and copy the file:
mkdir $HOME/.audifonos && cp "/proc/asound/card0/codec#0" "$HOME/.audifonos/con.txt"
Then I unplug the headphones and use the diff command which shows the different lines between the two files:
diff "/proc/asound/card0/codec#0" ".audifonos/con.txt"
There is some data that we are not interested in so we have to filter with grep so that it only shows the lines that have the word "Pin-ctls".
diff "/proc/asound/card0/codec#0" ".audifonos/con" | grep Pin-ctls
In case the command does not show anything on the screen, it means that we have headphones on. as it cannot return anything, it returns an error.
To see this error we type:
echo $?
If it shows us a one per screen, it tells us about the error.
on the other hand, if when we execute this it returns something then we have the headphones disconnected in which case it will not return an error:
echo $?
With this in mind and knowing bash it is easy to do it:
I download it, I give execution permissions to open it for the first time so that it “installs” (it only asks to connect headphones and copy the file that it explains at the beginning)
wget http://paste.desdelinux.net/?dl=5178 && chmod +x audifonos.sh && ./audifonos.sh
To finish I make it start automatically every time I turn on the pc
From Xfce I go to applications> configuration> Session and start> applications autostart> add and place the script
Do you happen to use a WM? It is that at least in Arch with Gnome-Shell 3.16 it preserves the changes in the volume controls, for example, when I connect the HDMI it shows me the maximum volume, when I connect headphones it shows me very low volume and in the built-in speakers almost the most.
Although in fact I was looking to do that for some time, it was a bitch having to lower the volume to be able to use the speakers so that the sound was not shrill or annoying for others. Thank you very much for the contribution.
for nothing 🙂, I use xfce 😛
I just remembered that I was once watching p0rn and had the headphones and the hdp disconnected and heard Shyla's moans: c
The good thing is that it was only a fragment of at least an eternal second and it sounded like horror movies when a prostitute was killed XD
Thinking it over I'm going to add it to favorites
Hahahahahaha the same thing happened to me when I unintentionally disconnected it at midnight and a good Hard Core sounded at full volume XD my family was scared: v
Good information will be useful to me at some point. Thanks a lot
You are not fooling me, you were watching for * or gay in Spanish and your headphones were disconnected xD
Thanks for the contribution, in Linux Mint the volume is preserved, for example if I put mute and then connect the headphones, in the headphones I will have sound and without them not.
Greetings.
hahaha, no but in those cases it also works (?)
Yes, it also works in those cases (͡ ° ͜ʖ ͡ °)
Good information, a suggestion, if the system supports 'devd' how do I proceed to copy or create this file?
[code] $ PREFIX / share / examples / cups / ulpt-cupsd.conf to $ PREFIX / etc / devd / [/ code]
I could not tell you, is not the cp command enough?
No, it says that directory does not exist and I don't know how to create either.
Heheheh well if I tell you it has happened to me on more than one occasion and with the same music so I write it down to install it later. Greetings and in the name of Heavy Metal thank you.
…… ~$ sudo pacman -S alsa-utils
[sudo] password for david:
sudo:pacman:command not found