New feature: enable change sound device

Bug #1047165 reported by Marek Tyburec
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Cuttlefish
Triaged
Wishlist
Unassigned

Bug Description

As I often change my sound device (eg. connect bluetooth headphones or hdmi cable) I always have to manually change the sound device settings to enable the device I have recetly connected and to turn off the other.

I found that there already is an event "When bluetooth device XY is connected then....", however there is no option to change sound device.

This is only a wishlist, not a bug.
Thanks for great app.

Tags: wishlist
Alex (noneed4anick)
Changed in cuttlefish:
status: New → Triaged
importance: Undecided → Wishlist
Revision history for this message
Alex (noneed4anick) wrote :

Hi Marek,

thanks for your feedback. This is a good idea and I will implement this, when I find some time. May I suggest a workaround for you?

Create a reflex with the bluetooth stimulus. Then use the advanced app-start command.
Select /usr/bin/pacmd as executable and write the following into the parameters field:
set-default-sink INDEX
Replace INDEX with the index of the sink you want to use, e.g 0 or 1
This may work, but currently I cannot test it, because I have no machine with two sinks availabe at the moment.

But if you like, you can try it and leave some feedback about how and if it works :-)

Revision history for this message
Marek Tyburec (marek-tyburec) wrote :

Hi,

thanks for your fast answer! I tried what you mentiened, but it has few issues.

When using with a bluetooth headset it successfully connects to my laptop, however it takes some time (eg 2 seconds) for computer to "realize" that it is a new sound device. Therefore the "pacmd set-default-sink 3" command is invalid, although it works few seconds later. Solution may be to use the timeout utility (I will try with custom script).

Secondly, it is not always sure which index will the device use. Therefore I would suggest:
When connected bluetooth-headset specified in app settings with name NAME, then:
Wait few seconds to make sure that system recognized new sound device and recheck "pacmd list sinks". There it should be possible to find device NAME and find out its index value. And finally use the command you mentioned.

Or the best solution would be to monitor sound devices (again maybe "pacmd list sinks") and when there is a new connected, then the above command should work.

Revision history for this message
Marek Tyburec (marek-tyburec) wrote :

Sorry, just mismatched timeout and sleep utility.

Revision history for this message
Marek Tyburec (marek-tyburec) wrote :

After few times of trying, this script finally worked. And one note to the command I mentioned above (pacmd list sinks) - when the device is connected eg. for second time, it is listed there twice. This is, however, not a problem of "pacmd list-cards".

#!/bin/bash
sleep 6
text=$(pacmd list-cards | tr -d '\n' | tr -d '\r' | tr -d '\t' | sed 's|index: |\n|g') ##get list of active card + filter out unneeded newlines + replace "index: " by newline
lines_count=$(echo "$text" | wc -l) ## Number of lines
for i in $(seq 1 1 $lines_count); do
  try_text=$(echo "$text" | awk NR==$i) ## use only $i line number
  if [[ "$try_text" =~ "Calypso" ]] ; then ## try to find device name Calypso
    index=$(echo "$try_text" | sed "s|name|\n|g" | awk NR==1) ## if found then get its index value
    index=$((index+1)); ## not sure why but here you have to add 1
  fi
done

pacmd set-default-sink $index
read

Revision history for this message
Alex (noneed4anick) wrote :

Thanks for the info, it will help me adapting an action from this.

It might be of interesset for you that cuttlefish provides a wait-action, so you don't need the sleep-command in your script. This way you can use the script without cuttlefish as well :-)

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.