Ubuntu On Sony Vaio FW Series

Tips & Tricks related to Sony Vaio FW series laptops

Headphones/Front switch script

with 4 comments

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&#91;email sign&#93;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.

Advertisements

Written by egaistek

July 7, 2009 at 07:49

Posted in Vaio

Tagged with , , , , ,

4 Responses

Subscribe to comments with RSS.

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

  2. […] P.S. How to link this script to AV Mode button (XF86Launch2) read in post about headphones switcher script. […]

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


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: