deweller / switchaudio-osx

Change the audio source for Mac OS X from the command line.
Other
1.19k stars 88 forks source link

Add output formats flag #20

Closed zph closed 5 years ago

zph commented 5 years ago

Hello!

I added extra output formats for printing device information:

Format Description
human current format (default)
cli comma separated for grep/awk usage
json json linewise format for jq

I also added a simple makefile to help with rebuilding the project from CLI.

I'm happy to contribute these changes back, but I'll admit I'm unfamiliar with writing good C. So please feel free to tweak the contribution to make it idiomatic and safe.

Thanks for writing this :). It solves an annoyance I had with wanting an easier way to switch audio devices.

zuckschwerdt commented 5 years ago

Looks good. Can you change this:

zph commented 5 years ago

@zuckschwerdt Will do, thank you for the feedback 👍 .

zph commented 5 years ago
$ ./build/Release/SwitchAudioSource -a -f json      
{"name": "Corsair VOID Wireless Gaming Dongle", "type": "input"}
{"name": "MacBook Pro Microphone", "type": "input"}
{"name": "DisplayPort", "type": "output"}
{"name": "Corsair VOID Wireless Gaming Dongle", "type": "output"}
{"name": "MacBook Pro Speakers", "type": "output"}

$ ./build/Release/SwitchAudioSource -a -f cli
Corsair VOID Wireless Gaming Dongle,input
MacBook Pro Microphone,input
DisplayPort,output
Corsair VOID Wireless Gaming Dongle,output
MacBook Pro Speakers,output

$ ./build/Release/SwitchAudioSource -a -f human
Corsair VOID Wireless Gaming Dongle (input)
MacBook Pro Microphone (input)
DisplayPort (output)
Corsair VOID Wireless Gaming Dongle (output)
MacBook Pro Speakers (output)

$ ./build/Release/SwitchAudioSource -a -f junk
Unknown format junk
Usage: ./build/Release/SwitchAudioSource [-a] [-c] [-t type] [-n] -s device_name
  -a             : shows all devices
  -c             : shows current device

  -f format      : output format (cli/human/json). Defaults to human.
  -t type        : device type (input/output/system).  Defaults to output.
  -n             : cycles the audio device to the next one
  -s device_name : sets the audio device to the given device by name
# exit_code=1

I've implemented your feedback and ^^ is a demonstration of the output.

Would you like me to squash this down to a single commit?

zuckschwerdt commented 5 years ago

Not needed. GitHub can squash on merge.

deweller commented 5 years ago

Looks good to me. Thanks!