Air-Tunes Speaker via Apple Skript switchen II

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 thoughts on “Air-Tunes Speaker via Apple Skript switchen II

  1. Tino says:

    Echt super, dass nun das Script für iTunes 10 zur Verfügung steht.
    Was mir jetzt noch fehlt ist die Möglichkeit als 3. Variante die Musik über alle Lautsprecher ausgeben zu können!

  2. hubi says:

    Na ja, die definierst Du einfach in check_these oder?

  3. Tino says:

    Nur wo und wie? Ein Lautsprecherpaar heißt bei mir “APE”, das andere heißt standardmäßig “Computer”. Ich bin leider nicht die Script-Leuchte! :)

  4. hubi says:

    musst mal etwas den Quellcode lesen…. nur ein bisschen…

    set check_these to {} –something like {“Name of Your Air-TunesDevice”}

    set uncheck_these to {} –something like {“Computer”}

  5. Tino says:

    Ja, das habe ich ja schon geändert!

    set check_these to {} –something like {“APE”}
    set uncheck_these to {} –something like {“Computer”}

    Das Script müsste aber auch beide aktivieren und nicht nur im Wechsel…Habe mich vielleicht etwas blöd ausgedrückt.

  6. hubi says:

    set check_these to {} –something like {“APE”,”Computer”}
    set uncheck_these to {} –something like {}

    ist dann die Lösung

  7. Tino says:

    Super Tip, geht aber leider nicht…habs gerade getestet.. :(

  8. Tino says:

    Asche auf mein Haupt! Habe die Änderungen im Infotext getätigt und nicht da, wo es sein sollte! *lach*
    Vielen Dank!!!

  9. […] den Beitrag weiterlesen: hubionmac.com » Air-Tunes Speaker via Apple Skript switchen II Bookmarken Sie uns, Danke! Mit Klick auf diese Icons kann man diese Webseite mit anderen Social […]

  10. Servus, gefällt mir gut was Du hier machst. Wo bekomm ich den RSS-Feed her? Matthias

  11. Sandra says:

    Cheerio, nice Content, should be developed! I have bookmarked for future reference! All the best for the future

  12. Chris says:

    Vielen Dank für das hilfreiche Skript.

    Ich habe es gerade ausprobiert und bekomme die folgende Fehlermeldung.

    error “„System Events“ hat einen Fehler erhalten: „table 1 of scroll area 1 of window 1 of application process \”iTunes\”“ kann nicht gelesen werden. Ungültiger Index.” number -1719 from table 1 of scroll area 1 of window 1 of application process “iTunes”

    Markiert ist folgende Codezeile:
    repeat with i from (count of every row) to 1 by -1 — Itterate through each row, looking for the criteria below

    Danke für die Rückmeldungen

  13. Hubi says:

    Das liegt daran dass Du vermutlich eine neuere iTunes Version benutzt, mit anderen Buttons…
    Das hier funktioniert mit meiner 10.5 Version:

    –Airtunes-Switch-Config-Script

    (**hubionmac.com 07.11.2011

    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 

    07.11.2011 made it working with iTunes 10.5

    **)

    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 10 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

    click button 3

    end tell

    end tell

    end tell

    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

Leave a Reply