Created
September 19, 2013 07:06
-
-
Save eagletmt/6619963 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# bluez 4.101 | |
# pulseaudio 4.0 | |
require 'dbus' | |
bd_addr = ARGV[0] | |
# Connect to the headset. | |
# Assumes that the headset has already paired by bluez-simple-agent. | |
bluez_service = DBus.system_bus.service('org.bluez') | |
adapter_path, = bluez_service.object('/').tap(&:introspect).DefaultAdapter | |
adapter = bluez_service.object(adapter_path).tap(&:introspect) | |
device_path, = adapter.FindDevice(bd_addr) | |
headset = bluez_service.object(device_path).tap(&:introspect)['org.bluez.Headset'] | |
if not headset.IsConnected.first | |
headset.Connect | |
end | |
# Lookup PulseAudio's bus. | |
server_lookup = DBus.session_bus.service('org.PulseAudio1').object('/org/pulseaudio/server_lookup1').tap(&:introspect)['org.PulseAudio.ServerLookup1'] | |
pulse_address = server_lookup['Address'] | |
# Get PulseAudio object. | |
pulse_bus = DBus::Connection.new(pulse_address) | |
pulse_bus.connect | |
pulse_service = pulse_bus.service('org.PulseAudio1') | |
pulse_core = pulse_service.object('/org/pulseaudio/core1').tap(&:introspect)['org.PulseAudio.Core1'] | |
# Set the headset as the fallback(default) sink. | |
sink_path, = pulse_core.GetSinkByName("bluez_sink.#{bd_addr.gsub(':', '_')}") | |
# Explicitly states that sink_path has ObjectPath type. | |
pulse_core['FallbackSink'] = ['o', sink_path] | |
# Set the headset as the fallback(default) source. | |
source_path, = pulse_core.GetSourceByName("bluez_source.#{bd_addr.gsub(':', '_')}") | |
# Explicitly states that source_path has ObjectPath type. | |
pulse_core['FallbackSource'] = ['o', source_path] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment