-1

How do I programmatically switch the current output device between built-in speakers on my MacBook Pro and a HomePod Mini (via Airplay) in AppleScript?

Marceli Wac
  • 375
  • 3
  • 13

1 Answers1

1

This can be done using the Switch Audio Source CLI program and the following script.

I am not affiliated with the switchaudio-osx in any way; I just found it useful for this task.

UPDATE:
I have moved the script to a repository to keep track of the changes needed.

Marceli Wac
  • 375
  • 3
  • 13
  • So I've tried this script, and it works great for switching from AirPlay to local, but when I try and get it to switch the other way, I get the following error: "Can’t get window "Audio Devices" of application process "Audio MIDI Setup"". – fatmcgav Feb 06 '23 at 14:46
  • @fatmcgav Good find! Thanks for lettming me know. I've managed to reproduce this and it seems to happen when the Audo MIDI Setup process is already active but does not have the "Audio Devices" window open. The window does not pop up on its own. This can be solved by adding the `reopen` command prior to activating the "Audio MIDI Setup". I have updated the code snippet to reflect this. – Marceli Wac May 05 '23 at 16:59