I like to switch various working positions at home. I want to make it change to the bluetooth speakers on power plugged in. And switch to internal speakers when unplugged. How to do it with some App or programming API?

1 Answer 1


Solved with a python script that calls SwitchAudioSource installed by brew install switchaudio-osx:

import psutil
import subprocess
import time

while True:
    if psutil.sensors_battery().power_plugged:
        subprocess.run(["SwitchAudioSource", "-s", "EDIFIER S301"])
        subprocess.run(["SwitchAudioSource", "-s", "MacBook Pro扬声器"])

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .