|
|
@ -4,48 +4,48 @@
|
|
|
|
# <swiftbar.hideRunInTerminal>true</swiftbar.hideRunInTerminal>
|
|
|
|
# <swiftbar.hideRunInTerminal>true</swiftbar.hideRunInTerminal>
|
|
|
|
# <swiftbar.hideLastUpdated>true</swiftbar.hideLastUpdated>
|
|
|
|
# <swiftbar.hideLastUpdated>true</swiftbar.hideLastUpdated>
|
|
|
|
# <swiftbar.hideDisablePlugin>true</swiftbar.hideDisablePlugin>
|
|
|
|
# <swiftbar.hideDisablePlugin>true</swiftbar.hideDisablePlugin>
|
|
|
|
|
|
|
|
# <swiftbar.hideSwiftBar>true</swiftbar.hideSwiftBar>
|
|
|
|
# <swiftbar.refreshOnOpen>true</swiftbar.refreshOnOpen>
|
|
|
|
# <swiftbar.refreshOnOpen>true</swiftbar.refreshOnOpen>
|
|
|
|
|
|
|
|
|
|
|
|
require "json"
|
|
|
|
require "json"
|
|
|
|
|
|
|
|
|
|
|
|
switch_audio_source = "/opt/homebrew/bin/SwitchAudioSource"
|
|
|
|
SWITCH_AUDIO_SOURCE = "/opt/homebrew/bin/SwitchAudioSource"
|
|
|
|
|
|
|
|
SOURCES = {
|
|
|
|
|
|
|
|
headset: { icon: "headphones", input: "Antlion USB Microphone", output: "CalDigit Thunderbolt 3 Audio" },
|
|
|
|
|
|
|
|
laptop: { icon: "play.laptopcomputer", input: "MacBook Pro Microphone", output: "MacBook Pro Speakers" },
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unless ARGV.empty?
|
|
|
|
unless ARGV.empty?
|
|
|
|
type, id = ARGV
|
|
|
|
audio_sources = `#{SWITCH_AUDIO_SOURCE} -a -f json`
|
|
|
|
`#{switch_audio_source} -t #{type} -i #{id}`
|
|
|
|
.lines(chomp: true)
|
|
|
|
|
|
|
|
.map {|x| JSON.parse(x) }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SOURCES.fetch(ARGV.shift.to_sym).each do |type, name|
|
|
|
|
|
|
|
|
src = audio_sources.find {|src| src.values_at("type", "name") == [type.to_s, name] }
|
|
|
|
|
|
|
|
id = src.fetch("id")
|
|
|
|
|
|
|
|
`#{SWITCH_AUDIO_SOURCE} -t #{type} -i #{id}`
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
audio_sources = `#{switch_audio_source} -a -f json`
|
|
|
|
input = JSON.parse(`#{SWITCH_AUDIO_SOURCE} -c -f json -t input`)
|
|
|
|
.lines(chomp: true)
|
|
|
|
output = JSON.parse(`#{SWITCH_AUDIO_SOURCE} -c -f json -t output`)
|
|
|
|
.map {|x| JSON.parse(x) }
|
|
|
|
active_source = SOURCES.find {|_,src|
|
|
|
|
.group_by {|x| x.fetch("type") }
|
|
|
|
src.values_at(:input, :output) == [input, output].map {|src| src.fetch("name") }
|
|
|
|
|
|
|
|
}
|
|
|
|
input = JSON.parse(`#{switch_audio_source} -c -f json -t input`)
|
|
|
|
|
|
|
|
output = JSON.parse(`#{switch_audio_source} -c -f json -t output`)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
puts ":waveform: | symbolize=true"
|
|
|
|
icon = active_source ? active_source.fetch(1).fetch(:icon) : "questionmark.bubble"
|
|
|
|
|
|
|
|
puts ":waveform:: :#{icon}: | symbolize=true"
|
|
|
|
puts "---"
|
|
|
|
puts "---"
|
|
|
|
|
|
|
|
|
|
|
|
audio_sources.each do |type,sources|
|
|
|
|
SOURCES.each do |name, sources|
|
|
|
|
sources.each do |source|
|
|
|
|
params = {
|
|
|
|
name = source.fetch("name")
|
|
|
|
symbolize: true,
|
|
|
|
id = source.fetch("id")
|
|
|
|
checked: name == active_source.fetch(0),
|
|
|
|
|
|
|
|
bash: __FILE__,
|
|
|
|
sf_type = case type
|
|
|
|
terminal: false,
|
|
|
|
when "input" then ":mic.fill:"
|
|
|
|
param0: name,
|
|
|
|
when "output" then ":speaker.wave.2.fill:"
|
|
|
|
}
|
|
|
|
else fail "Unexpected type: #{type}"
|
|
|
|
|
|
|
|
end
|
|
|
|
icon = sources.fetch(:icon)
|
|
|
|
|
|
|
|
puts ":#{icon}: | #{params.map {|k,v| "#{k}=#{v}"}.join(" ")}"
|
|
|
|
params = {
|
|
|
|
|
|
|
|
symbolize: true,
|
|
|
|
|
|
|
|
checked: [input, output].include?(source),
|
|
|
|
|
|
|
|
bash: __FILE__,
|
|
|
|
|
|
|
|
terminal: false,
|
|
|
|
|
|
|
|
param0: type,
|
|
|
|
|
|
|
|
param1: id,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
puts "#{sf_type} #{name} | #{params.map {|k,v| "#{k}=#{v}"}.join(" ")}"
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|