Closed zph closed 5 years ago
Looks good. Can you change this:
char * FORMAT_CLI = "cli";
and put the string in the strcmp
char * format;
format = strdup(optarg);
, use optarg
in strcmp
strcmp
instead of strncmp
strcmp
for "human"
and error in the else
case (print and exit)@zuckschwerdt Will do, thank you for the feedback 👍 .
$ ./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?
Not needed. GitHub can squash on merge.
Looks good to me. Thanks!
Hello!
I added extra output formats for printing device information:
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.