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
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"])
else:
subprocess.run(["SwitchAudioSource", "-s", "MacBook Pro扬声器"])
time.sleep(10)