Created
November 1, 2023 01:26
-
-
Save ndrake/3c0840f03662a21900a81ec22ab734a1 to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
## Switch audio output device | |
*/ | |
// Name: Switch Audio | |
// Description: Switch audio output device (Mac only) | |
// Author: Nate Drake | |
// Install SwitchAudioSource with `brew install switchaudio-osx` | |
import "@johnlindquist/kit" | |
const SwitchAudioSourcePath = '/opt/homebrew/bin/SwitchAudioSource' | |
const sasExists = await pathExists(SwitchAudioSourcePath) | |
if (sasExists) { | |
const currentOutput = await $`${SwitchAudioSourcePath} -c` | |
const items = await $`${SwitchAudioSourcePath} -a -t output` | |
const choices = items.stdout.trim().split(/\r?\n/).filter(o => o !== currentOutput.stdout.trim()) | |
let output = await arg( | |
{ | |
placeholder: 'Pick ouput device' | |
}, | |
choices | |
) | |
await $`${SwitchAudioSourcePath} -s ${output} -t output` | |
} else { | |
await div(md(`ERROR: Please install SwitchAudioSource`)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment