Airfoil, MacMini, Spotify & Homey - Music throughout the house with airplay

Just to share: I have setup a MacMini running spotify and Airfoil to play music throughout the house via airplay.

to overcome the problem that some airplay speakers can go offline and airfoil doesn’t reconnect to them automatically I have used AppleScript to create an App which checks every 60 seconds if an airplay speaker becomes available and reconnects it to Airfoil.
Airfoil can also play to chrome speakers.

This happens for my at my garden speaker (“Tuin” - old airport Express) which will disconnect if I kill the power.

By adding Spotify, Airfoil and the AppleScript at startup of the automatic login, the system will get back to the original setup when the MacMini reboots.

Homey is used to control the volume output, next and previous song through the Spotify App on Homey. Of course when you have Spotify on your mobile phone you can control which playlist is being transmitted. I just wanted to have it in one Domotica app.

For those interested in the AppleScript I used, here goes:

tell application “Airfoil”
repeat while true
try
set aSpeaker to first speaker whose name is “Tuin”
if not (connected of aSpeaker) then
connect to aSpeaker
end if
end try
delay 60
end repeat
end tell


You can repeat the try blok for every speaker you want to automatically reconnect.

Let me know your thoughts on how to improve this setup!
Thanks,
Jan

1 Like