Skip to content

Instantly share code, notes, and snippets.

@CodeBrauer
Last active January 18, 2022 11:58
Show Gist options
  • Save CodeBrauer/e33689216f5ae7fcad20b07ad62fa7cd to your computer and use it in GitHub Desktop.
Save CodeBrauer/e33689216f5ae7fcad20b07ad62fa7cd to your computer and use it in GitHub Desktop.
quick and dirty script to toggle audio device (switch between speaker and headphones) using switchaudio-osx and BetterTouchTool (for a keyboard shortcut)

README

  1. brew install switchaudio-osx
  2. Check your audio devices with switchaudiosource -a
  3. Replace Mac mini Lautsprecher and Externe Kopfhörer with your ouput channels
  4. Place the script somewhere your user can execute it (do a chmod +x audiotoggle.sh)
  5. Copy the json and paste it to BTT. Edit the script path and you're done.
#!/bin/bash
# /usr/local/bin/switchaudiosource -a
CURRENT=$(/usr/local/bin/switchaudiosource -c)
echo $CURRENT;
if [[ "$CURRENT" == "Externe Kopfhörer" ]]; then
/usr/local/bin/switchaudiosource -s "Mac mini Lautsprecher"
/usr/bin/osascript -e 'display notification "Mac mini Lautsprecher" with title "Audioausgang geändert"'
else
/usr/local/bin/switchaudiosource -s "Externe Kopfhörer"
/usr/bin/osascript -e 'display notification "Externe Kopfhörer" with title "Audioausgang geändert"'
fi
{
"BTTTriggerClass" : "BTTTriggerTypeKeyboardShortcut",
"BTTPredefinedActionType" : 172,
"BTTPredefinedActionName" : "Apple Script starten (blockierend)",
"BTTInlineAppleScript" : "do shell script \"\/Users\/codebrauer\/scripts\/audiotoggle.sh\"",
"BTTAdditionalConfiguration" : "8519680",
"BTTEnabled2" : 1,
"BTTKeyboardShortcutKeyboardType" : 3253,
"BTTRepeatDelay" : 0,
"BTTUUID" : "E86A6EE6-0B34-4607-8D94-9AE303AF29CB",
"BTTTriggerOnDown" : 1,
"BTTNotesInsteadOfDescription" : 0,
"BTTLayoutIndependentChar" : "F12",
"BTTEnabled" : 1,
"BTTModifierMode" : 0,
"BTTShortcutKeyCode" : 111,
"BTTShortcutModifierKeys" : 8519680,
"BTTOrder" : 5,
"BTTDisplayOrder" : 0,
"BTTAutoAdaptToKeyboardLayout" : 0
}
@CodeBrauer
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment