You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.8 KiB

#!/usr/bin/env ruby
# <swiftbar.hideAbout>true</swiftbar.hideAbout>
# <swiftbar.hideRunInTerminal>true</swiftbar.hideRunInTerminal>
# <swiftbar.hideLastUpdated>true</swiftbar.hideLastUpdated>
# <swiftbar.hideDisablePlugin>true</swiftbar.hideDisablePlugin>
2 years ago
# <swiftbar.hideSwiftBar>true</swiftbar.hideSwiftBar>
# <swiftbar.refreshOnOpen>true</swiftbar.refreshOnOpen>
require "json"
2 years ago
SWITCH_AUDIO_SOURCE = "/opt/homebrew/bin/SwitchAudioSource"
SOURCES = {
2 years ago
headset: { icon: "headphones", input: "Antlion USB Microphone", output: "CalDigit TS4 Audio - Front" },
2 years ago
laptop: { icon: "play.laptopcomputer", input: "MacBook Pro Microphone", output: "MacBook Pro Speakers" },
}
unless ARGV.empty?
2 years ago
audio_sources = `#{SWITCH_AUDIO_SOURCE} -a -f json`
.lines(chomp: true)
.map {|x| JSON.parse(x) }
2 years ago
source = SOURCES.fetch(ARGV.shift.to_sym)
%i[input output].each do |xput|
name = source.fetch(xput)
src = audio_sources.find {|src| src.values_at("type", "name") == [xput.to_s, name] }
2 years ago
id = src.fetch("id")
2 years ago
`#{SWITCH_AUDIO_SOURCE} -t #{xput} -i #{id}`
2 years ago
end
end
2 years ago
input = JSON.parse(`#{SWITCH_AUDIO_SOURCE} -c -f json -t input`)
output = JSON.parse(`#{SWITCH_AUDIO_SOURCE} -c -f json -t output`)
active_source = SOURCES.find {|_,src|
src.values_at(:input, :output) == [input, output].map {|src| src.fetch("name") }
}
2 years ago
icon = active_source ? active_source.fetch(1).fetch(:icon) : "questionmark.bubble"
puts ":waveform:: :#{icon}: | symbolize=true"
puts "---"
2 years ago
SOURCES.each do |name, sources|
params = {
symbolize: true,
2 years ago
checked: active_source && (name == active_source.fetch(0)),
2 years ago
bash: __FILE__,
terminal: false,
param0: name,
2 years ago
refresh: true,
2 years ago
}
icon = sources.fetch(:icon)
puts ":#{icon}: | #{params.map {|k,v| "#{k}=#{v}"}.join(" ")}"
end