I created this script because I was frustrated with macOS constantly changing my input device every time I connected my Bluetooth headset. I had to manually set my preferred microphone every single time, and it became a nuisance.
This script ensures that your preferred input device (e.g., a dedicated microphone) remains selected on macOS, even when new devices (like Bluetooth headsets) are connected. By default, macOS automatically switches input devices when a new audio device is connected, which can disrupt workflows. This script continuously monitors the active input device and switches it back to your preferred microphone if it changes.
- Automatically sets your preferred input device when it is changed.
- Runs continuously in the background to ensure consistent audio input.
- Works seamlessly with macOS and SwitchAudioSource.
Before using the script, make sure you have the following:
- Homebrew installed. If not, install it by running:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - SwitchAudioSource installed via Homebrew:
brew install switchaudio-osx
- Clone this repository:
git clone git@github.com:matheusrrocha/input-device-switcher.git cd autoinput-device-switcher - Make the script executable:
chmod +x fix_input_device.sh
- You can find the exact name of your devices by running:
SwitchAudioSource -t input -a
- Run the script:
./fix_input_device.sh "my Device Name"
- Open the Automator app on macOS.
- Create a new Application.
- Add the action Run Shell Script and paste the command:
/path/to/fix_input_device.sh - Save the application and add it to System Settings > Users & Groups > Login Items.
- Ensure that SwitchAudioSource is installed and accessible in your $PATH.
- You can customize the monitoring interval by modifying the sleep duration in the script.
If you encounter SwitchAudioSource: command not found, ensure that Homebrew is installed and the SwitchAudioSource binary is accessible. Add Homebrew’s binary directory to your PATH: