LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-29-2014, 03:19 PM   #1
Tadaen
Member
 
Registered: Sep 2005
Distribution: Arch
Posts: 210

Rep: Reputation: 39
Switch outputs pulseaudio in Arch


I wrote this trying to automate switching to my bluetooth headset when I activate it. It works one way, changing to the onboard analog sound sink when no bluetooth is connected. Doesn't change inputs to the bluetooth sinks though. I'm at a loss as to what I'm doing wrong. I had this working fine a couple weeks ago. What is wrong with this script.

Code:
#!/bin/bash
#Tadaen Sylvermane
#mybluetooth

##### variables #####

## sink names
# onboard analog sink name
ANALOG=alsa_output.pci-0000_00_1b.0.analog-stereo
# miisport bt headset sink name
HEADSET=bluez_sink.50_19_09_00_C9_3D
# jbl charge bt speaker sink name
SPEAKER=bluez_sink.00_1D_DF_EE_00_81
## sink indexes
# active sink index
ACTIVESINK=$(pacmd list-sinks | grep index | grep "*" | awk '{print $3}')
# analog sink index
if pacmd list-sinks | grep -B 1 -i "$ANALOG" | grep index | grep "*" ; then
  ANALOGOB=$(pacmd list-sinks | grep -B 1 -i "$ANALOG" | grep index | awk '{print $3}')
else
  ANALOGOB=$(pacmd list-sinks | grep -B 1 -i "$ANALOG" | grep index | awk '{print $2}')
fi
# bt headset sink index
if pacmd list-sinks | grep -B 1 -i "$HEADSET" | grep index | grep "*" ; then
  HEADSETSINK=$(pacmd list-sinks | grep -B 1 -i "$HEADSET" | grep index | awk '{print $3}')
else
  HEADSETSINK=$(pacmd list-sinks | grep -B 1 -i "$HEADSET" | grep index | awk '{print $2}')
fi
# bt speaker sink index
if pacmd list-sinks | grep -B 1 -i "$SPEAKER" | grep index | grep "*" ; then
  SPEAKERSINK=$(pacmd list-sinks | grep -B 1 -i "$SPEAKER" | grep index | awk '{print $3}')
else
  SPEAKERSINK=$(pacmd list-sinks | grep -B 1 -i "$SPEAKER" | grep index | awk '{print $2}')
fi
## current sink inputs
SINKINPUTS=$(pacmd list-sink-inputs | grep index | awk '{print $2}')

##### begin script #####

btpowerup() { # enable bluetooth on login - set to run on startup
	echo -e "power on\nexit\n" | bluetoothctl
}

setsink() {
	chsinks() {
		pacmd set-default-sink "$1"
		for input in $SINKINPUTS
		do
			pacmd move-sink-input "$input" "$1"
		done
	}
	if [[ "$HEADSETSINK" ]] ; then
		if [[ "$ACTIVESINK" != "$HEADSETSINK" ]] ; then
		   	chsinks "$HEADSETSINK"
		fi
	elif [[ "$SPEAKERSINK" ]] ; then
		if [[ "$ACTIVESINK" != "$SPEAKERSINK" ]] ; then
		   	chsinks "$SPEAKERSINK"
		fi
	else
		chsinks "$ANALOGOB"
	fi
}

case "$1" in
	poweron) # enable bluetooth power
		btpowerup
		;;
	sinkswap) # swap sinks
		setsink
		;;
	*)
		echo "usage $0 {poweron | sinkswap}"
		;;
esac

##### end script #####
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Pulseaudio limits to 4 audio outputs junior-s Linux - Software 0 03-25-2014 03:44 AM
how to convert unformatted binary files/outputs to netcdf outputs in linux? sarasari Programming 2 03-11-2014 11:30 PM
Want to switch to Arch Linux. But what about Security Fixes in it? s.verma Arch 3 12-26-2013 08:43 AM
LXer: How To Switch To ALSA Or OSS Instead Of PulseAudio In A Few Seconds LXer Syndicated Linux News 0 03-30-2010 09:00 PM
laptop only works with X.org if i switch between different outputs. REALLY wierd. jimjamjahaa Linux - Hardware 11 07-31-2006 04:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration