Skip to content

Instantly share code, notes, and snippets.

@0xjessel
Created March 10, 2025 06:50
Show Gist options
  • Select an option

  • Save 0xjessel/4968b16dd93bb70d19abe06facafa43b to your computer and use it in GitHub Desktop.

Select an option

Save 0xjessel/4968b16dd93bb70d19abe06facafa43b to your computer and use it in GitHub Desktop.
Script to toggle audio output between MacBook Pro speakers and JCHEN AirPods Pro
#!/bin/bash
# Script to toggle audio output between MacBook Pro speakers and JCHEN AirPods Pro
# Requires SwitchAudioSource: brew install switchaudio-osx
# Get current audio output device
CURRENT_DEVICE=$(SwitchAudioSource -c)
# Define device names based on your system
MACBOOK_SPEAKERS="MacBook Pro Speakers"
AIRPODS="JCHEN AirPods Pro"
# Toggle between devices
if [[ "$CURRENT_DEVICE" == "$MACBOOK_SPEAKERS" ]]; then
# Currently using MacBook speakers, switch to AirPods
SwitchAudioSource -s "$AIRPODS"
echo "Switched to JCHEN AirPods Pro"
else
# Currently using something else, switch to MacBook speakers
SwitchAudioSource -s "$MACBOOK_SPEAKERS"
echo "Switched to MacBook Pro Speakers"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment