Headphone recognition

Questions about hardware,drivers and peripherals
Forum rules
Before you post please read how to get help
User avatar
Kaye
Level 5
Level 5
Posts: 939
Joined: Fri Feb 06, 2009 5:05 pm
Location: Boston College
Contact:

Headphone recognition

Postby Kaye » Sat Mar 07, 2009 10:59 am

Hey everyone,

Since I have to go into ossxmix and mute my speakers manually every time I plug in my headphones, I wrote a small bash script so that I can simply hit <Control>h and mute/unmute my speakers:

Code: Select all

#!/bin/bash

MODE=$(ossmix jack.int-speaker.mode)
if [ "$MODE" = "Value of jack.int-speaker.mode set to mix2" ]; then
    ossmix jack.int-speaker.mode input
    ossmix jack.black.mode4 input
else
    ossmix jack.int-speaker.mode mix2
    ossmix jack.black.mode4 mix2
fi

(Or something along those lines, I'm on another system right now).
The script works perfectly, but I was wondering if it were possible to take it to the next level. Is there any way for me to monitor whether or not headphones are plugged in, and have this script run every time they're plugged in or removed? I would be happy enough with this hack, it would at least make me feel like a driver was running things for me :)

Thanks in advance,
Kaye
"In somnis veritas"
Antivirus or defragging?
Image

Husse
Level 23
Level 23
Posts: 19590
Joined: Sun Feb 11, 2007 7:22 am
Location: Near Borås Sweden

Re: Headphone recognition

Postby Husse » Sun Mar 08, 2009 10:22 am

That is a tough one
Because if your headphones don't switch of your speakers the chances are that they are not recognised
And even if they were you'd have to do something very "basic" (like an udev rule)
You could try to run

Code: Select all

lsmod | grep snd

with the headphones plugged in an not plugged in
I don't think there's a difference, but who knows (I have only got USB headphones so I can't check)
It's no longer just a mechanical thing - plugging in triggers a reaction of some kind that should be dealt with by Linux
Some node appearing or disappearing...
Image
Don't fix it if it ain't broken, don't break it if you can't fix it


Return to “Hardware Support”

Who is online

Users browsing this forum: No registered users and 3 guests