esprits300 wrote:Beautiful pages! question. I'm trying to do something similar with airplay regarding the status and volume of EACH airplay speaker. I have an AppleScript to turn on and off the speaker and set the volume, BUT i can't find any way to get the current status or volume. how did you go about doing that? thanks!
First I created a variable for each speaker with the format [speaker name]_vol, and two variables called VolUp and VolDown. In my control page, when you click on the + it sets VolUp to the name of the speaker (- set VolDown).
I then have a trigger that runs when VolUp is changed (a different trigger for VolDown). The trigger runs this bit of code:
#Get value of VolUp
set thespeaker to value of variable "VolUp"
#Create and empty list
set speakerlist to {}
if thespeaker is not "" then
#Get the current speaker volume level
set thespeakervol to thespeaker & "_vol"
set rawVolume to value of variable thespeakervol as integer
#As long as the volume is not 11 turn it up 1 level
#the vol script is identical to this except that it checks for vol <0 and subtracts 1
if rawVolume is less than 11 then
set rawVolume to (rawVolume + 1) as integer
end if
#Convert 1-11 to 0% - 100%
set newvolume to ((rawVolume * 0.09) * 100) / 100
tell application "Airfoil"
#If VolUp is equal to Main then get a list of all the speakers (we want to increase all of their volumes)
if thespeaker = "Main" then
set allspeakers to every speaker
#otherwise just get the speaker in VolUp
else
set allspeakers to every speaker whose name is thespeaker
end if
# loop through the list of speakers
repeat with thisspeaker in all speakers
#If the speaker is connected set the speakers volume
if (connected of thisspeaker) then
set the end of speakerlist to name of thisspeaker
if newvolume > 0.9 then
set (volume of thisspeaker) to 1
else
set (volume of thisspeaker) to newvolume
end if
end if
end repeat
end tell
#reset speaker volume level
if thespeaker = "Main" then
set value of variable "Main_vol" to rawVolume
end if
#reset speaker volume level
repeat with thisspeaker in speakerlist
set the value of variable (thisspeaker & "_vol") to rawVolume
end repeat
set value of variable "VolUp" to ""
end if