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

**URL:** <https://community.homey.app/t/airfoil-macmini-spotify-homey-music-throughout-the-house-with-airplay/116212>\
**Category:** Tutorials\
**Tags:** homey-pro\
**Created:** [September 17, 2024, 11:01am UTC](https://community.homey.app/t/airfoil-macmini-spotify-homey-music-throughout-the-house-with-airplay/116212 "2024-09-17T11:01:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jan-Paul\_Krijgsman](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jan-paul_krijgsman/32/113613_2.png) [@Jan-Paul\_Krijgsman](https://community.homey.app/u/Jan-Paul_Krijgsman)\
**Post date:** [September 17, 2024, 11:01am UTC](https://community.homey.app/t/airfoil-macmini-spotify-homey-music-throughout-the-house-with-airplay/116212/1 "2024-09-17T11:01:22Z")

</div>

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
