Air-Tunes Speaker via Apple Skript switchen II

10/09/2010
Die ursprüngliche Version konnte mit iTunes 8 und 9 noch funktionieren... mit iTunes 10 hat sich das GUI wieder etwas geändert. Fall-Line hatte sich der Aktualisierung bereits angenommen, diese Version sollte aber unter jeder System-Sprache funktionieren. Zudem hat das Skript noch ein kleines Update erfahren. Man kann eine Konfiguration vorgeben oder ohne Vorgabe die aktuelle Einstellung in iTunes einfach nur switchen...
Code zum markieren einmal anklicken Code im Skript-Editor öffnen

--Airtunes-Switch-Config-Script

(**hubionmac.com 10.09.2010

for addition info: http://hubionmac.com/wordpress/?p=2303

orig. Version by http://fall-line.com/2010/09/control-airplayairtunes-feature-of-itunes-with-applescript/

if check_these und uncheck_these = {} then your

Airtunes-Config will be switched the other way around....


Makes use of GUI-Skripting, hopefully Apple will add native AppleScript-Support in iTunes for

Airtunes some day 


**)


set check_these to {} --something like {"Name of Your Air-TunesDevice"}

set uncheck_these to {} --something like {"Computer"}


my check_gui_scripting_is_active()

my check_if_iTunes_window_visible()

my press_speaker_button_and_open_all_speakers()

my check_boxes_and_close_window(check_these, uncheck_these)


on press_speaker_button_and_open_all_speakers()

tell application "iTunes"

activate

tell application "System Events"

tell application process "iTunes"

click button 8 of window "iTunes" --Press the iTunes 10 Speaker Button

key code 125 using {command down} -- this is essentiall hitting page down (command + down arrow)

delay 1

keystroke return

delay 1

end tell

end tell

end tell

end press_speaker_button_and_open_all_speakers


on check_boxes_and_close_window(check_these, uncheck_these)

--if check_these und uncheck_these = {} then your

--Airtunes-Config will be switched the other way around....

tell application "iTunes"

activate

tell application "System Events"

tell application process "iTunes"

tell window 1

tell table 1 of scroll area 1

set check_computer_allowed to false

repeat with i from (count of every row) to 1 by -1 -- Itterate through each row, looking for the criteria below

set rowcount to count of rows

set a to rowcount

if rowcount > 0 then

tell group 1 of row i

activate -- Drill into the object group of each row, so we don't have to later.

-- If "Speaker in Room A" is turned off (value of checkbox 1 = 0), turn it on. Otherwise do nothing

if check_these is {} and uncheck_these = {} then

if i > 1 and value of checkbox 1 as integer = 0 then

set check_computer_allowed to true

end if

if i > 1 then

click checkbox 1

else

if check_computer_allowed is true then

click checkbox 1

end if

end if

else

if (description of checkbox 1) is in check_these and value of checkbox 1 as integer = 0 then

click checkbox 1

end if

if (description of checkbox 1) is in uncheck_these and value of checkbox 1 as integer = 1 then

click checkbox 1

set a to (description of checkbox 1)

end if

end if

end tell

end if

end repeat

end tell

end tell

end tell

end tell

close window 1

end tell

end check_boxes_and_close_window


on check_if_iTunes_window_visible()

tell application "iTunes"

activate

tell application "System Events"

tell application process "iTunes"

--check if itunes Window is frontmost

if (count of every window) = 0 or (name of window 1 ≠ "iTunes") then

keystroke "1" using {command down, option down}

end if

end tell

end tell

end tell

end check_if_iTunes_window_visible



to check_gui_scripting_is_active()

tell application "System Events" to set isUIScriptingEnabled to UI elements enabled

if isUIScriptingEnabled = false then

tell application "System Preferences"

activate

set current pane to pane "com.apple.preference.universalaccess"

display dialog "Your system is not properly configured to run this script.

         Please select the \"Enable access for assistive devices\"

         checkbox and trigger the script again to proceed."

return

end tell

end if

end check_gui_scripting_is_active

15 Comments

Air-Tunes Speaker via Apple Skript switchen

18/12/2008
Code zum markieren einmal anklicken Code im Skript-Editor öffnen

--©hubionmac.com 18.12.2008

-- GUI-Skript mit dem die aktuelle Air-Tunes ausgabe verändert wird,

-- die aktuelle Airtunes-Lautsprecher-Auswahl werden quasi 

activate application "iTunes"

tell application "System Events"

get system attribute "sysv"

if result is greater than or equal to 4144 then -- Mac OS X 10.3.0

if UI elements enabled then

tell application process "iTunes"

if (name of button 15 of window "iTunes" as text) ≠ "" then

set noe to false

click button 15 of window "iTunes" --Den ITunes Lautsprecher Button drücken

delay 0.25

-- in der Liste ganz nach unten gehene (mehrere Lautsprecher auswählen Menüpunkt 

repeat with i from 1 to 5

key code 125

end repeat

keystroke return

try

repeat with i from 1 to (count of every UI element of window 1)

tell UI element i of window 1

set rowcount to count of rows

if rowcount > 0 then

if (value of checkbox 1 of row rowcount) as integer = 0 then

--dieser part beugt einer Fehlermeldung vor... 

--welcher? einfach mal diesen if-Block entfernen und Du wirst sehen =)

click checkbox 1 of row rowcount

set rowcount to rowcount - 1

end if

repeat with rownr from 1 to rowcount

click checkbox 1 of row rownr

end repeat

end if

end tell

end repeat

end try

keystroke "w" using command down

else

set noe to true

end if

end tell

else

beep

display dialog "GUI Scripting is not enabled" & return & return & "Open System Preferences and check Enable Access for Assistive Devices in the Universal Access preference pane, then run this script again." with icon stop

if button returned of result is "OK" then

tell application "System Preferences"

activate

set current pane to pane "com.apple.preference.universalaccess"

end tell

end if

end if

else

beep

display dialog "This computer cannot run this script" & return & return & "The script uses GUI Scripting technology, which requires an upgrade to Mac OS X 10.3 Panther or newer." with icon caution buttons {"Quit"} default button "Quit"

end if

end tell

if noe = true then

tell application "iTunes" to display dialog "nö, keine Airtunes Lautsprecher angeschlossen bzw. kein Button da, wo man so etwas auswählen könnt :-/"

end if

Läuft bis iTunes 9... Eine Lösung für iTunes 10 hat fall-line parat.
4 Comments