[pulseaudio-discuss] Keeping a USB mic selected when unplugged & plugged in again

Colin Guthrie gmane at colin.guthr.ie
Mon Sep 6 00:36:39 PDT 2010

'Twas brillig, and Whit Blauvelt at 02/09/10 13:00 did gyre and gimble:
> On Thu, Sep 02, 2010 at 08:45:18AM +0100, Colin Guthrie wrote:
>>> I can't find where the checked/unchecked status is stored, or how to
>>> hard-code it so the microphone always is selected just as soon as the
>>> headset is plugged in. This is not good when trying to answer a Skype call.
>>> Is there some way to make the microphone default to on? 
>> There isn't really a smooth way to do this with the current code sadly.
>> ...
>> http://colin.guthr.ie/2010/02/this-is-the-route-to-hell/
> Wow. That's an impressively thorough analysis and proposal. Glad you're
> working on it.
> For my specific case, is a kludgey fix possible? Instead of having to mouse
> through System > Preferences > Sound > Input to check what at this point is
> the only radio button there, is a command-line script possible that would
> send the same signal as checking that button? I've always got open terminal
> sessions, so could far more quickly type "restoremic" or something than do
> all that mousing.
> If I knew what that script should do, I could also just have it run from
> cron every minute - have it check if the mic is plugged in since that shows
> in .pulse/nnnn-default-source, and if it is plugged in force it to be
> actually selected.

You could run: pacmd set-default-source foo

(where foo is the name of your source). The name should remain static,
so you should be able to put this in an alias.

What this command will not do, however, is move any currently active
streams recording from the old default to the new one. Depending on
circumstances, this may not be important. It would be possible to script
this too, but it'll be a little tricky.

> Or even better, there might be a way to piggyback on whatever is noticing
> the mic's been plugged in, and have it then turn it on by running the
> auxilliary script by default. Obviously this would be a kludge, not a
> universal solution. But I'd be happy.

Sadly there is no way to do this, but in theory a module that just
listens for such events and runs scripts would be possible. But not
until someone writes it :D

> A major design advantage of *nix is that close to 100% of it can be
> configured and run with text files and terminal commands. If sound is moving
> away from that, becoming dependent on a GUI interface with commands that
> can't be done except through a GUI, that's unfortunate. GUI's are great when
> they work, but for anything complex the traditional "edit files, run
> commands" *nix approach allows more thorough and fine-grained control.

pactl and pacmd are fairly powerful, but could probably do with some
love. I'd like to see their functionality unified as they have diverged
a little in recent times.

> So, is there a command-line way to do what checking that radio button
> accomplishes?

Yes, but it's not too easy. I thing the radio button does the following:
 1. Change the device in PA
 2. Moves any streams currently running over to the new device.

I could be wrong on the above, as I've not looked at the code, but I
know it's more "active" than just changing the current default.



Colin Guthrie

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]

More information about the pulseaudio-discuss mailing list