[pulseaudio-discuss] Using "expect" to feed pacmd

Colin Guthrie gmane at colin.guthr.ie
Fri Sep 10 02:07:25 PDT 2010

'Twas brillig, and Whit Blauvelt at 10/09/10 04:40 did gyre and gimble:
>> #! /usr/bin/expect
>> spawn pacmd
>> expect ">>>"
>> send "set-default-source alsa_input.usb-Generic_FREETALK_Everyman_0000000001-00-Everyman.analog-stereo\r"
>> expect ">>>"
>> send "exit=\r"
> Oops, that last line is triple wrong. Actually, the script as given works,
> but it shouldn't. There's a typo of an added "=", and even worse there's the
> use of "exit" which would be appropriate in many shells, but in pacmd tells
> the utility to kill the daemon - not what's wanted, but it fortunately fails
> to do that even with the "=" removed.
> Happily, leaving that last line off entirely works. The script does need the
> second expect line for ">>>" that's before it, for some reason. Then expect
> gets out of the shell without an explicit exit or ctrl-C or whatever,
> happily.
> I'm sure the script could be expanded to also send the output somewhere
> specific, or whatever. You could set up a whole row of buttons in your panel
> to send system-specific commands, or groups of them, to pacmd via expect
> scripts.
> Makes me feel a little better about the prospects of pulse, even if this is
> way too hackish in its little way.

Contrary to the comment that pacmd takes no command line options, you
can just give it commands, so there is no need for this complicated
expect script:

pacmd set-default-source

Should work fine.

The default.pa is processed on PA startup, so if you were to put such
commands at the end of the default.pa (or better create your own
default.pa in ~/.pulse/default.pa with the following contents:

.include /etc/pulse/default.pa

You'll notice the use of .nofail and .fail there. This starts a generic
block where any errors are ignored. This will mean that if you do not
have the USB plugged in when pulse starts, it will not care that it did
not manage to set the default.

You mentioned earlier that it's "fragile", but this is entirely expected
behaviour, so I'm not sure that that description is really appropriate.



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