Skip to content

Instantly share code, notes, and snippets.

@ndrake
Created November 1, 2023 01:26
Show Gist options
  • Save ndrake/3c0840f03662a21900a81ec22ab734a1 to your computer and use it in GitHub Desktop.
Save ndrake/3c0840f03662a21900a81ec22ab734a1 to your computer and use it in GitHub Desktop.
/*
## 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