Toggle speakers without using pull down menu?

how to setup a macro to choose a speaker without pulling down menu ?

Hi, @Pyxis; try this macro: Set Sound Output

1 Like

you use Apple Script to do it ?

Yes, AppleScript within the Execute an AppleScript action.

The AppleScript code employs GUI Scripting because these settings are not scriptable, per se. For more information, refer to the macro comments including the Version History.

right !
i'd thought of AppleScript is the only to achieve it and you confirm that.
now i need sometime to study your scripts. thank you !

1 Like

Ah, but they are... if you install switchaudio-osx from the command line. :wink:

1 Like

Hi @cdthomer.

Scriptable as in AppleScript or accessible as in the switchaudio-osx features via the shell?

As I mentioned in the Set Sound Output thread, when using switchaudio-osx I was unable to access my HomePod and other AirPlay devices. But I suppose it's possible that this limitation has since been addressed.

1 Like

Hey @_jims, AFAIK the same limitation still exists. But if one doesn’t use AirPlay devices then switchaudio-osx is a fast, simple solution.

Including AirPods?

Should I assume switchaudio-osx features via the shell?


I'm curious; do you drive switchaudio-osx using a KM macro?

Thanks @cdthomer!

If the AirPods are already connected (even if they’re not the currently selected audio device), then it can switch to them. If they are not even connected, then I use AppleScript... namely the one below.

AppleScript (click to expand/collapse)
use framework "IOBluetooth"
use scripting additions
set AirPodsName to "Chris AirPods 3"
on getFirstMatchingDevice(deviceName)
	repeat with device in (current application's IOBluetoothDevice's pairedDevices() as list)
		if (device's nameOrAddress as string) contains deviceName then return device
	end repeat
end getFirstMatchingDevice
on toggleDevice(device)
	if not (device's isConnected as boolean) then
		device's openConnection()
		return "Connecting " & (device's nameOrAddress as string)
	else
		device's closeConnection()
		return "Disconnecting " & (device's nameOrAddress as string)
	end if
end toggleDevice
return toggleDevice(getFirstMatchingDevice(AirPodsName))

Accessible assuming already connected via Bluetooth.

I do! See the screenshot for a simple example of using Keyboard Maestro to trigger switchaudio-osx.

Action Screenshot (click to expand/collapse)

1 Like