### Install SwitchAudio OSX Source: https://context7.com/deweller/switchaudio-osx/llms.txt Install the utility via Homebrew or build it directly from the source repository. ```bash # Install via Homebrew brew install switchaudio-osx # Or build from source git clone https://github.com/deweller/switchaudio-osx.git cd switchaudio-osx make build ``` -------------------------------- ### Install switchaudio-osx via Homebrew Source: https://github.com/deweller/switchaudio-osx/blob/master/README.md Use this command to install the utility on macOS systems with Homebrew. ```shell brew install switchaudio-osx ``` -------------------------------- ### Scripting and Automation Examples Source: https://context7.com/deweller/switchaudio-osx/llms.txt Integrate SwitchAudio OSX into shell scripts using JSON output and conditional logic. These examples demonstrate device toggling, availability checks, and ID parsing. ```bash #!/bin/bash # Toggle between headphones and speakers CURRENT=$(SwitchAudioSource -c) if [ "$CURRENT" = "MacBook Pro Speakers" ]; then SwitchAudioSource -s "External Headphones" else SwitchAudioSource -s "MacBook Pro Speakers" fi # Check if a specific device is available before switching if SwitchAudioSource -a | grep -q "USB Audio Device"; then SwitchAudioSource -s "USB Audio Device" echo "Switched to USB Audio Device" else echo "USB Audio Device not connected" fi # Parse JSON output with jq to get device IDs DEVICE_ID=$(SwitchAudioSource -a -t output -f json | jq -r 'select(.name=="External Headphones") | .id') if [ -n "$DEVICE_ID" ]; then SwitchAudioSource -i "$DEVICE_ID" fi # Create a microphone mute toggle script for hotkey binding # Save as ~/bin/toggle-mic.sh and bind to a keyboard shortcut #!/bin/bash SwitchAudioSource -m toggle -t input # Optionally show notification osascript -e 'display notification "Microphone toggled" with title "Audio"' ``` -------------------------------- ### Cycle to Next Audio Device Source: https://context7.com/deweller/switchaudio-osx/llms.txt The -n flag cycles through available devices, wrapping around to the start of the list. Use -t all to cycle all device types simultaneously. ```bash # Cycle to next output device SwitchAudioSource -n # Output: output audio device set to "External Headphones" # Cycle again to get next device SwitchAudioSource -n # Output: output audio device set to "USB Audio Device" # Cycle to next input device SwitchAudioSource -n -t input # Output: input audio device set to "USB Microphone" # Cycle all device types (input, output, system) SwitchAudioSource -n -t all # Output: # input audio device set to "USB Microphone" # output audio device set to "External Headphones" # system audio device set to "External Headphones" ``` -------------------------------- ### Set Audio Device by Name Source: https://context7.com/deweller/switchaudio-osx/llms.txt Switch to a specific device using its exact name. Use -t to specify type or 'all' for multiple types. ```bash # Set output device by name SwitchAudioSource -s "External Headphones" # Output: output audio device set to "External Headphones" # Set input device by name SwitchAudioSource -t input -s "USB Audio Device" # Output: input audio device set to "USB Audio Device" # Set system output device SwitchAudioSource -t system -s "MacBook Pro Speakers" # Output: system audio device set to "MacBook Pro Speakers" # Set all device types (input, output, system) with the same name SwitchAudioSource -t all -s "USB Audio Device" # Output: # input audio device set to "USB Audio Device" # output audio device set to "USB Audio Device" # system audio device set to "USB Audio Device" ``` -------------------------------- ### SwitchAudioSource CLI Reference Source: https://github.com/deweller/switchaudio-osx/blob/master/README.md Reference for the SwitchAudioSource command-line utility, covering device selection, listing, and muting functionality. ```APIDOC ## CLI Command: SwitchAudioSource ### Description A command-line utility to switch the audio source on Mac OS X. It allows for listing devices, switching the active device, and toggling mute states. ### Parameters #### Flags - **-a** (flag) - Optional - Shows all devices - **-c** (flag) - Optional - Shows current device - **-f** (string) - Optional - Output format (cli/human/json). Defaults to human. - **-t** (string) - Optional - Device type (input/output/system). Defaults to output. - **-m** (string) - Optional - Sets the mute status (mute/unmute/toggle). - **-n** (flag) - Optional - Cycles the audio device to the next one - **-i** (string) - Optional - Sets the audio device to the given device by id - **-u** (string) - Optional - Sets the audio device to the given device by uid or a substring of the uid - **-s** (string) - Optional - Sets the audio device to the given device by name ### Usage Example ```shell # Toggle mute for the current input device SwitchAudioSource -m toggle -t input # Switch output to a specific device name SwitchAudioSource -s "Built-in Digital Output" ``` ``` -------------------------------- ### Set Audio Device by UID Source: https://context7.com/deweller/switchaudio-osx/llms.txt Use the -u flag to set devices by full or partial UID. Partial matching is effective for long, vendor-specific identifiers. ```bash # Get device UIDs first SwitchAudioSource -a -f json # Output: # {"name": "USB Headset", "type": "output", "id": "76", "uid": "AppleUSBAudioEngine:Logitech:G Pro:ABC123:1"} # Set device by full UID SwitchAudioSource -u "AppleUSBAudioEngine:Logitech:G Pro:ABC123:1" # Output: output audio device set to "Device with UID: AppleUSBAudioEngine:Logitech:G Pro:ABC123:1" # Set device by UID substring (matches partial UID) SwitchAudioSource -u "Logitech" # Output: output audio device set to "Device with UID: AppleUSBAudioEngine:Logitech:G Pro:ABC123:1" # Set input device by UID substring SwitchAudioSource -t input -u "USB" # Output: input audio device set to "Device with UID: AppleUSBAudioEngine:Generic:USBMic:DEF456:1" ``` -------------------------------- ### List Audio Devices Source: https://context7.com/deweller/switchaudio-osx/llms.txt Display available audio devices using various filters and output formats. ```bash # List all output devices (default) SwitchAudioSource -a # Output: # MacBook Pro Speakers # External Headphones # USB Audio Device # List all input devices SwitchAudioSource -a -t input # Output: # MacBook Pro Microphone # USB Audio Device # List all devices with CLI format (name,type,id,uid) SwitchAudioSource -a -f cli # Output: # MacBook Pro Speakers,output,42,BuiltInSpeakerDevice # External Headphones,output,76,AppleUSBAudioEngine:Vendor:Product:12345 # MacBook Pro Microphone,input,38,BuiltInMicrophoneDevice # List all output devices in JSON format SwitchAudioSource -a -t output -f json # Output: # {"name": "MacBook Pro Speakers", "type": "output", "id": "42", "uid": "BuiltInSpeakerDevice"} # {"name": "External Headphones", "type": "output", "id": "76", "uid": "AppleUSBAudioEngine:Vendor:Product:12345"} ``` -------------------------------- ### Show Current Audio Device Source: https://context7.com/deweller/switchaudio-osx/llms.txt Query the currently active audio device for input, output, or system sounds. ```bash # Show current output device (default) SwitchAudioSource -c # Output: MacBook Pro Speakers # Show current input device SwitchAudioSource -c -t input # Output: MacBook Pro Microphone # Show current system output device SwitchAudioSource -c -t system # Output: MacBook Pro Speakers # Get current device in JSON format for scripting SwitchAudioSource -c -t output -f json # Output: {"name": "MacBook Pro Speakers", "type": "output", "id": "42", "uid": "BuiltInSpeakerDevice"} # Get current input device in CLI format SwitchAudioSource -c -t input -f cli # Output: MacBook Pro Microphone,input,38,BuiltInMicrophoneDevice ``` -------------------------------- ### List Audio Devices Source: https://context7.com/deweller/switchaudio-osx/llms.txt Lists all available audio devices with options to filter by type and output format. ```APIDOC ## List All Audio Devices ### Description Displays all available audio devices of a specified type with configurable output format. ### Parameters #### Query Parameters - **-a** (flag) - Required - List all devices - **-t** (string) - Optional - Filter by device type (input, output, system) - **-f** (string) - Optional - Output format (human, cli, json) ``` -------------------------------- ### Set Audio Device by Name Source: https://context7.com/deweller/switchaudio-osx/llms.txt Switches the active audio device by providing its exact name. ```APIDOC ## Set Audio Device by Name ### Description Switch to a specific audio device by providing its exact name. ### Parameters #### Query Parameters - **-s** (string) - Required - Name of the device - **-t** (string) - Optional - Device type (input, output, system, all) ``` -------------------------------- ### C API Functions Source: https://context7.com/deweller/switchaudio-osx/llms.txt Core functions for interacting with macOS audio devices via the SwitchAudio OSX library. ```APIDOC ## C API Functions ### Description Functions provided by `audio_switch.h` to manage audio devices, including retrieval of device IDs, setting active devices, and controlling mute states. ### Functions - **getCurrentlySelectedDeviceID(ASDeviceType typeRequested)**: Returns the AudioDeviceID for the currently selected device of the specified type. - **getDeviceName(AudioDeviceID deviceID, char *deviceName)**: Populates the provided buffer with the name of the specified device. - **getDeviceUID(AudioDeviceID deviceID)**: Returns the unique identifier (UID) string for the specified device. - **getRequestedDeviceID(char *requestedDeviceName, ASDeviceType typeRequested)**: Finds a device ID by its human-readable name. - **getRequestedDeviceIDFromUIDSubstring(char *requestedDeviceUID, ASDeviceType typeRequested)**: Finds a device ID by a substring of its UID. - **setDevice(AudioDeviceID newDeviceID, ASDeviceType typeRequested)**: Sets the active audio device for the specified type. - **cycleNext(ASDeviceType typeRequested)**: Cycles to the next available device for the specified type. - **setMute(ASDeviceType typeRequested, ASMuteType mute)**: Controls the mute state (Unmute, Mute, or Toggle) for the specified device type. - **showAllDevices(ASDeviceType typeRequested, ASOutputType outputRequested)**: Outputs a list of all devices in the requested format (Human, CLI, or JSON). ``` -------------------------------- ### C API Definitions for Audio Switching Source: https://context7.com/deweller/switchaudio-osx/llms.txt Defines enumerations and function prototypes for controlling audio devices on macOS. Includes types for devices, output formats, and mute states. ```c #include "audio_switch.h" // Device type enumeration typedef enum { kAudioTypeUnknown = 0, kAudioTypeInput = 1, // Microphones kAudioTypeOutput = 2, // Speakers/Headphones kAudioTypeSystemOutput = 3, // System sounds kAudioTypeAll = 4 // All device types } ASDeviceType; // Output format enumeration typedef enum { kFormatHuman = 0, // Simple device name kFormatCLI = 1, // Comma-separated: name,type,id,uid kFormatJSON = 2 // JSON object } ASOutputType; // Mute control enumeration typedef enum { kUnmute = 0, kMute = 1, kToggleMute = 2 } ASMuteType; // Get the currently selected device ID for a given type AudioDeviceID getCurrentlySelectedDeviceID(ASDeviceType typeRequested); // Get device name from device ID void getDeviceName(AudioDeviceID deviceID, char *deviceName); // Get device UID from device ID const char *getDeviceUID(AudioDeviceID deviceID); // Find device ID by name AudioDeviceID getRequestedDeviceID(char *requestedDeviceName, ASDeviceType typeRequested); // Find device ID by UID substring AudioDeviceID getRequestedDeviceIDFromUIDSubstring(char *requestedDeviceUID, ASDeviceType typeRequested); // Set the audio device int setDevice(AudioDeviceID newDeviceID, ASDeviceType typeRequested); // Cycle to the next device int cycleNext(ASDeviceType typeRequested); // Control mute state OSStatus setMute(ASDeviceType typeRequested, ASMuteType mute); // Display all devices void showAllDevices(ASDeviceType typeRequested, ASOutputType outputRequested); ``` -------------------------------- ### Set Audio Device by ID Source: https://context7.com/deweller/switchaudio-osx/llms.txt Switch to a device using its numeric ID. IDs are system-assigned and may change upon reconnection. ```bash # Get device IDs first SwitchAudioSource -a -f cli # Output: # MacBook Pro Speakers,output,42,BuiltInSpeakerDevice # External Headphones,output,76,AppleUSBAudioEngine:Vendor:Product:12345 # Set output device by ID SwitchAudioSource -i 76 # Output: output audio device set to "Device with ID: 76" # Set input device by ID SwitchAudioSource -t input -i 38 ``` -------------------------------- ### Show Current Audio Device Source: https://context7.com/deweller/switchaudio-osx/llms.txt Queries the currently active audio device for a specific type. ```APIDOC ## Show Current Audio Device ### Description Displays the currently selected audio device for a specific type. ### Parameters #### Query Parameters - **-c** (flag) - Required - Show current device - **-t** (string) - Optional - Filter by device type (input, output, system) - **-f** (string) - Optional - Output format (human, cli, json) ``` -------------------------------- ### Toggle Mute State for Input Device Source: https://github.com/deweller/switchaudio-osx/blob/master/README.md Use this command to toggle the mute status of the currently selected input device. ```shell SwitchAudioSource -m toggle -t input ``` -------------------------------- ### Set Audio Device by ID Source: https://context7.com/deweller/switchaudio-osx/llms.txt Switches the active audio device using its numeric CoreAudio device ID. ```APIDOC ## Set Audio Device by ID ### Description Switch to a specific audio device using its numeric device ID. ### Parameters #### Query Parameters - **-i** (integer) - Required - Numeric device ID - **-t** (string) - Optional - Device type (input, output, system) ``` -------------------------------- ### Mute and Unmute Audio Devices Source: https://context7.com/deweller/switchaudio-osx/llms.txt Control mute states using the -m flag with mute, unmute, or toggle modes. Specify the device type with -t. ```bash # Toggle mute on current input device (microphone) SwitchAudioSource -m toggle -t input # Output: Setting device MacBook Pro Microphone to muted # Toggle again to unmute SwitchAudioSource -m toggle -t input # Output: Setting device MacBook Pro Microphone to unmuted # Explicitly mute output device SwitchAudioSource -m mute -t output # Output: Setting device MacBook Pro Speakers to muted # Explicitly unmute output device SwitchAudioSource -m unmute -t output # Output: Setting device MacBook Pro Speakers to unmuted # Mute both input and output simultaneously SwitchAudioSource -m mute -t all # Output: # Setting device MacBook Pro Microphone to muted # Setting device MacBook Pro Speakers to muted ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.