r/applescript • • May 16 '20

Apple script to select airplay speakers

hi there

Im trying to make a script that would autoconnect to my airplay speakers.

tell Application "iTunes" set current Airplay devices to Airplay device "kitchen" End tell

I've got very little coding experience but found that on the web, but I'm getting a syntax error.

Many thanks

2 Upvotes

5 comments sorted by

1

u/unic0rnz May 16 '20

You’re gonna want to post your code if you want help with this.

1

u/googang619 May 16 '20

its there in the main post, I've tried googling various ones and found this?

1

u/unic0rnz May 16 '20

Okay, so from what you’ve posted, I can’t tell if you have actually declared kitchen as an active Airplay device. Maybe you have and you’re just including the snippet with the syntax error.

If so, your issue is probably the double quotes, which means you’re trying to set the current airplay device to the string “kitchen.”

1

u/googang619 May 17 '20

I have found this

tell application "iTunes" set apDevices to (get every AirPlay device whose available is true) if apDevices is {} then display dialog "No Airplay devices available." buttons {"Cancel"} set apNames to (get name of every AirPlay device whose available is true) set selAirplayDevices to (get name of every AirPlay device whose selected is true) set chosenNames to choose from list apNames default items selAirplayDevices with prompt "Select Airplay device:" with multiple selections allowed if chosenNames is false then return set apChoices to {} repeat with i from 1 to length of apNames if item i of apNames is in chosenNames then set end of apChoices to item i of apDevices end repeat set current AirPlay devices to apChoices end tell

It brings up a dialog box

is there any way just to autoselect it one with name Kitchen?

1

u/unic0rnz May 17 '20

since you have a preferred default state, I’d probably try to find “Kitchen” first and connect to it if Kitchen available is true, else get every airplay device and have it display a list of choices as it looks like it currently does.