Skip to content

Instantly share code, notes, and snippets.

@jwmann
Last active September 18, 2020 19:26
Show Gist options
  • Save jwmann/46f57cedfb5bcc0ff7d87e84abc3b306 to your computer and use it in GitHub Desktop.
Save jwmann/46f57cedfb5bcc0ff7d87e84abc3b306 to your computer and use it in GitHub Desktop.

Revisions

  1. jwmann revised this gist Sep 18, 2020. 1 changed file with 7 additions and 4 deletions.
    11 changes: 7 additions & 4 deletions toggleAudioOutput.sh
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,18 @@
    #! /bin/bash
    # Author: James W Mann (jwmann)
    # Dependencies: homebrew, SwitchAudioSource
    # Dependencies: homebrew, SwitchAudioSource (https://github.com/deweller/switchaudio-osx)
    # Notes: If SwitchAudioSource, the script will install it automatically
    # See all audio devices: $> SwitchAudioSource -a
    # Manually switch with: $> SwitchAudioSource -s device_name

    toggle_audio() {
    brew=/usr/local/bin/brew
    if [ -f $brew ]; then
    switchAudioSource=$($brew --prefix)/bin/SwitchAudioSource
    if [ -f $switchAudioSource ]; then
    currentOutput="$($switchAudioSource -c)"
    audioOutputA="All Speakers"
    audioOutputB="Yeti Stereo Microphone"
    audioOutputA="Vanatoo T0"
    audioOutputB="Built-in Digital Output"
    case $currentOutput in
    $audioOutputA )
    switchTo=$audioOutputB
    @@ -31,4 +34,4 @@ toggle_audio() {
    return 1
    fi
    }
    toggle_audio
    toggle_audio
  2. jwmann revised this gist Jan 7, 2020. No changes.
  3. jwmann revised this gist Jan 7, 2020. No changes.
  4. jwmann created this gist Jan 7, 2020.
    34 changes: 34 additions & 0 deletions toggleAudioOutput.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    #! /bin/bash
    # Author: James W Mann (jwmann)
    # Dependencies: homebrew, SwitchAudioSource
    # Notes: If SwitchAudioSource, the script will install it automatically
    toggle_audio() {
    brew=/usr/local/bin/brew
    if [ -f $brew ]; then
    switchAudioSource=$($brew --prefix)/bin/SwitchAudioSource
    if [ -f $switchAudioSource ]; then
    currentOutput="$($switchAudioSource -c)"
    audioOutputA="All Speakers"
    audioOutputB="Yeti Stereo Microphone"
    case $currentOutput in
    $audioOutputA )
    switchTo=$audioOutputB
    ;;
    $audioOutputB )
    switchTo=$audioOutputA
    ;;
    esac
    $switchAudioSource -s "$switchTo" > /dev/null 2>&1
    osascript -e 'display notification "'"${switchTo//\"/\\\"}"'" with title "Audio Output"'
    return 0
    else
    osascript -e 'display notification "SwitchAudioSource binary not found. Installing now." with title "Error Switching Audio"'
    $brew install switchaudio-osx && osascript -e 'display notification "SwitchAudioSource binary successfully installed." with title "Audio Output"' && toggle_audio
    return 0
    fi
    else
    osascript -e 'display notification "Homebrew not found. Please install homebrew." with title "Error Switching Audio"'
    return 1
    fi
    }
    toggle_audio