Airplay über Apple Script steuern

Hallo zusammen,

gibt es eine Möglichkeit in Itunes 10.5.x Airplay (Airtunes) per Apple Script zu aktivieren ? Sprich: ich führ das Script aus und die Airport Express xyz geht an.

Es gibt schon ein Script: fall-line.com/2010/12/control-ai … plescript/
aber das geht nur mit 10.1.x

Wär top wenn einer eine Idee hat.

Hi,

ich habe so ein Script schon seit längerer Zeit bei mir herumliegen. Habe es schnell mal an iTunes 10.5.2 angepasst.

In den beiden ersten Zeilen kannst Du die Lautsprecher konfigurieren. Die Variable set check_these muss die Bezeichnung des Lautsprechers enthalten der aktiviert werden soll. uncheck_these enthält den Namen des Lautsprechers, der deaktiviert werden soll. In dieser Form würde das Script also die Ausgabe direkt auf dem Mac aktivieren und den Airplay Lautsprecher Apple TV trennen. Wenn das Script umgekehrt funktionieren soll, dann musst Du halt die Variablen check_these und uncheck_these vertauschen, bzw. deren Inhalt. Am besten legst Du Dir zwei Scripte mit den unterschiedlichen Konfigurationen an. Dann kanst Du bequem hin und her schalten.

Das Script selbst holt das iTunes Fenster in den Vordergrund und bedient die Oberfläche per GUI Scripting. Es vergehen ein paar Sekunden bis das Script vollständig gurchgelaufen ist. Also nicht ungeduldig werden, wenn sich zwischendurch nichts rührt :wink:

lg

Michael

set check_these to {"Computer"}
set uncheck_these to {"Apple TV"}

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 28 of window "iTunes"
				key code 125 using {command down}
				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)
	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
							set rowcount to count of rows
							set a to rowcount
							if rowcount > 0 then
								tell group 1 of row i
									activate
									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 "iTunes"
		tell application "System Events"
			tell application process "iTunes"
				click button 3 of window "Mehrere Lautsprecher"
			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"
				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

Hiho,

Vielen Dank für das Script.

Aber leider funktioniert es nicht so ganz.

error "„System Events“ hat einen Fehler erhalten: „button 28 of window \"iTunes\" of application process \"iTunes\"“ kann nicht gelesen werden. Ungültiger Index." number -1719 from button 28 of window "iTunes" of application process "iTunes"

Ja, hab es auch gerade gemerkt. Das ist der Nachteil bei GUI Scripting :wink:

Schuld daran ist das iTunes Fenster, bzw diese Zeile im Script:

click button 28 of window "iTunes"

Button 28 ist der Airplay Knopf im iTunes Fenster - aber nur dann, wenn iTunes in der iTunes Store Ansicht ist :wink:

Für Musik, Filme und Radio muss die Zeile

click button 10 of window "iTunes"

lauten.

Bei “Leihobjekte” ist es

click button 11 of window "iTunes"

Für TV-Sendungen ist es

click button 12 of window "iTunes"

iTunes startet scheinbar immer mir der zuletzt eingestellten Ansicht. Ich habe noch keine Möglichkeit gefunden, iTunes per AS mit einer bestimmten Ansicht zu starten. Vielleicht findet sich da noch etwas. Bis dahin kann ich Dir leider nur empfehlen, das Script auf die hauptsächlich benutze Ansicht einzurichten und dafür zu sorgen, dass iTunes auch immer mit dieser startet.

lg

Michael

Vielen Dank für die Anpassung :smile:

Es läuft, 1A.

Jetzt hab ich das Script getrennt. Eins für ein und eins für aus.

Gibts irgendeinen Trick, wie ich

a) das Script beschleunigen kann ? Da es eine Weile dauert bis er auf “Mehrere Lautsprecher…” “klickt”.
b) alles im Hintergrund laufen lassen kann ?

Guten Morgen,

mir ist selbst nicht ganz klar, warum das Script so lange braucht. Deshalb habe ich hier keinen Tipp für eine Optimierung.

Das GUI Scripting funktioniert leider nur dann, wenn die Anwendung im Vordergrund ist. Im Grunde kann man sich das wie ein Makro vorstellen, welches auf die entsprechenden Knöpfe drückt. Es funktioniert also nicht im Hintergrund.

lg

Michael

Mir ist das auch nicht klar. Was ist falsch dran, die betreffende Airport-Station auszuwählen und spielen zu lassen (in iTunes?) Wofür brauch ich da ein Script?

Ich will es ja über einen anderen Rechner steuern, sonst wär es ja sinnfrei :smile:

Falls es jmd. interessiert:

Aufruf aus dem Terminal

osascript /Library/Scripts/dein-script.scpt

Gibt es die möglichkeit ein shell script über HTTP-Request aufzurufen ?