Music: Simple Airplay Script

Hi there,

I'm trying to create a touch bar button that will enable Airplay for the Music app (or, if connected, also switches back to the Computer). Right now, I think I made a simple mistake that makes it connect to Airplay, but won't switch to the Computer when hitting the button again. Can somebody give me a hint?

tell application "Music"
if current AirPlay devices is equal to AirPlay device "Dining Room" then
	set current AirPlay devices to AirPlay device "Computer"
else
	set current AirPlay devices to AirPlay device "Dining Room"
end if
end tell

Thank you!

In your script you're just checking wether the AirPlay device "Dining Room" currently exists, but you don't check for its connection status.
You'll have to introduce a variable that refers to that precise "selected" state :slightly_smiling_face:

tell application "Music"
	set AirPlayName to name of the first AirPlay device whose selected is true
	if AirPlayName is "Dining Room" then
		set current AirPlay devices to AirPlay device "Computer"
		return "Music playing on Computer"
	else
		set current AirPlay devices to AirPlay device "Dining Room"
		return "Music playing on Dining Room"
	end if
end tell

This should work.
For more AirPlay actions, check also the AirPlay group of my PHoeNiX Preset :slightly_smiling_face:

F.eg. the button itself could be an Apple Script Widget that displays an icon of your computer if the music is played here, or of the HiFi if "Dining Room" is selected :wink:

1 Like

Big thanks! Works like expected. :slight_smile:

1 Like
Imprint | Privacy Policy