Headphones/Front switch script
I’m not defining a “hippo” model for “snd-hda-intel” to make headphones detection about we talk earlier. Because I’m using my headphones plug very rarely, I decided to write a shell script to switch sound to headphone and back and link it to to S1 button. This information could help you if you want to make S1 button to do something else too.
Here is a switch script, when you run it, it detects if headphones are switched on then it switch it off and vice-versa. Front mixer channel will be switched off if headphones switched on and vice-versa.
#!/bin/bash # by Anton Veretenenko <anton[email sign]veretenenko.ru> is_front_on=`amixer -c 0 cget numid=2,iface=MIXER,name='Front Playback Switch' | grep -i -c -P -e "values=on,on"` if [ "$is_front_on" == "1" ] then amixer -c 0 cset numid=2,iface=MIXER,name='Front Playback Switch' off amixer -c 0 cset numid=3,iface=MIXER,name='Headphone Playback Switch' on else amixer -c 0 cset numid=2,iface=MIXER,name='Front Playback Switch' on amixer -c 0 cset numid=3,iface=MIXER,name='Headphone Playback Switch' off fi
To link S1 button to this script (make a shortcut) you need to delete shortcut from System->Preferences->Keyboard Shortcuts for this button, if you have it. I guess you saw that S1 button named as “XF86Launch1” in keyboard shortcuts, you need this name later.
Open gconf-editor (Alt+F2, type gconf-editor, Run). On the left tree select apps->metacity->global_keybindings the on the right you should see a list of keys, select one you like (I choose “run_command_1”) and edit it (right click, Edit Key), enter name of S1 button (“XF86Launch1”) into value field. Then select “keybinding_commands” on the left.
Edit “command_1” key, into value field you should enter path to the script, in my case it is “/home/egaistek/scripts/alsa-front-mute”. That’s all, it should work now.
P.S. Do not forget to add executable permissions to a script file (chmod +x in terminal or File->Properties, Permissions tab, set “Allow executing file as program” in Nautilus/File Explorer)
P.P.S. This works only for Gnome without Compiz running. If you want to add shortcuts with Compiz, use Compiz configuration tools.

This is a good idea for something to allocate to the S1 button.
Something I would like is to be able to have a simple script or button press to switch sound output to the HDMI sound device for when I attach my laptop to my TV. Any idea how this might be done?
Joc
July 7, 2009 at 15:52
Sure, read my newer post.
egaistek
July 8, 2009 at 13:24
[…] P.S. How to link this script to AV Mode button (XF86Launch2) read in post about headphones switcher script. […]
HDMI sound output switcher for PulseAudio « Ubuntu On Sony Vaio FW Series
July 8, 2009 at 13:24
On my vaio, using the following line worked to make my sound cards function as is proper:
in file /etc/modprobe.d/alsa-base.conf
options snd-hda-intel model=sony-assamd
I saw some references to using the hippo model instead, but this model seems to work perfectly on my vaio.
KillerMonk
November 3, 2009 at 01:26