#!/bin/ksh -p case $1 in on|1) set -- 0 on "" ;; off|0) set -- 1 off -- ;; *) echo $0 on/off ; exit 1 esac echo 'set oo to "" tell application "System Events" tell application process "iTunes" set airplayButton to button 12 of window "iTunes" -- changes on updates set thetitle to get value of attributes of airplayButton whose name is "AXTitle" '$3'if thetitle is not {"2 Speakers"} then try window "Multiple Speakers" -- error if not open on error tell airplayButton click delay 0.1 key code 125 using {command down} delay 0.1 keystroke " " end tell end try delay 0.5 tell window "Multiple Speakers" of application process "iTunes" of application "System Events" activate -- Make sure we are on the right window tell table 1 of scroll area 1 activate -- Drill into the Table that contains our speakers -- "Computer" should always be row #1 if value of checkbox 1 of group 1 of row 1 as integer = 0 then click checkbox 1 of group 1 of row 1 set oo to oo & "Turning local computer on\n" end if repeat with i from 2 to (count of every row) set rowcount to count of rows if rowcount > 0 then tell group 1 of row i activate if value of checkbox 1 as integer = '$1' then click checkbox 1 set oo to oo & "Turning row " & i & " '$2'\n" end if end tell end if end repeat end tell end tell tell application "iTunes" to activate tell application "System Events" to tell process "iTunes" to tell window "Multiple Speakers" to keystroke "w" using {command down} '$3'end if end tell end tell return oo' | osascript