iTunes Info in XML schreiben

M

MrKnx

Mitglied
Thread Starter
Dabei seit
30.01.2014
Beiträge
44
Reaktionspunkte
1
Hi Leute,
ich habe vor, einige iTunesinformationen in eine XML zu schreiben, um diese mit meinem Hausautomationserver auslesen zu können. Leider wehrt sich mein Script an dem current track und will einfach nicht durchlaufen. Kann mir vielleicht jemand weiterhelfen?
Bitte nicht schlagen, Apllescripte sind nicht mein Spezialgebiet.... :d
Code:
[FONT=Helvetica Neue]on [COLOR=#0433ff]run[/COLOR][/FONT]
[FONT=Helvetica Neue]    set [COLOR=#4f8f00]filepath[/COLOR] to ((([COLOR=#012fbe]path to[/COLOR] [COLOR=#5730be]desktop[/COLOR]) as [COLOR=#0433ff]Unicode text[/COLOR]) & "iTunes_Info.xml")[/FONT]
[COLOR=#4F8F00][FONT=Helvetica Neue][COLOR=#000000]    set [/COLOR]xmldata[COLOR=#000000] to [/COLOR]xmlheader[COLOR=#000000]() & [/COLOR][COLOR=#812fdc]return[/COLOR][/FONT][/COLOR]

[FONT=Helvetica Neue]    tell [COLOR=#0433ff]application[/COLOR] "System Events" to ([COLOR=#812fdc]name[/COLOR] of [COLOR=#0433ff]processes[/COLOR]) contains "iTunes"[/FONT]
[FONT=Helvetica Neue]    if [COLOR=#812fdc]result[/COLOR] is [COLOR=#812fdc]true[/COLOR] then[/FONT]
[FONT=Helvetica Neue]        tell [COLOR=#0433ff]application[/COLOR] "iTunes"[/FONT]
[FONT=Helvetica Neue]            try[/FONT]
[FONT=Helvetica Neue]                set [COLOR=#4f8f00]player_state[/COLOR] to (get [COLOR=#812fdc]player state[/COLOR] as [COLOR=#0433ff]string[/COLOR])[/FONT]
[FONT=Helvetica Neue]                set [COLOR=#4f8f00]volume_info[/COLOR] to (get [COLOR=#812fdc]sound volume[/COLOR] as [COLOR=#0433ff]string[/COLOR])[/FONT]
[FONT=Helvetica Neue]                set [COLOR=#4f8f00]airplay_state[/COLOR] to (get [COLOR=#812fdc]AirPlay enabled[/COLOR] as [COLOR=#0433ff]string[/COLOR])[/FONT]
[FONT=Helvetica Neue]                set [COLOR=#4f8f00]equalizer_state[/COLOR] to (get [COLOR=#812fdc]EQ enabled[/COLOR] as [COLOR=#0433ff]string[/COLOR])[/FONT]
[FONT=Helvetica Neue]                set [COLOR=#4f8f00]current_album[/COLOR] to (get [COLOR=#812fdc]album[/COLOR] of the [COLOR=#812fdc]current track[/COLOR] as [COLOR=#0433ff]string[/COLOR])[/FONT]
[FONT=Helvetica Neue]                set [COLOR=#4f8f00]current_artist[/COLOR] to (get [COLOR=#812fdc]artist[/COLOR] of the [COLOR=#812fdc]current track[/COLOR] as [COLOR=#0433ff]string[/COLOR])[/FONT]
[FONT=Helvetica Neue]                set [COLOR=#4f8f00]current_track[/COLOR] to (get [COLOR=#812fdc]current track[/COLOR] as [COLOR=#0433ff]string[/COLOR])[/FONT]
[FONT=Helvetica Neue]            end try[/FONT]
[FONT=Helvetica Neue]        end tell[/FONT]
[FONT=Helvetica Neue]        set [COLOR=#4f8f00]xmldata[/COLOR] to [COLOR=#4f8f00]xmldata[/COLOR] & "<iTunes>ON</iTunes>"[/FONT]
[FONT=Helvetica Neue]        set [COLOR=#4f8f00]xmldata[/COLOR] to [COLOR=#4f8f00]xmldata[/COLOR] & "<state>" & [COLOR=#4f8f00]player_state[/COLOR] & "</state>"[/FONT]
[FONT=Helvetica Neue]        set [COLOR=#4f8f00]xmldata[/COLOR] to [COLOR=#4f8f00]xmldata[/COLOR] & "<volume>" & [COLOR=#4f8f00]volume_info[/COLOR] & "</volume>"[/FONT]
[FONT=Helvetica Neue]        set [COLOR=#4f8f00]xmldata[/COLOR] to [COLOR=#4f8f00]xmldata[/COLOR] & "<airplay>" & [COLOR=#4f8f00]airplay_state[/COLOR] & "</airplay>"[/FONT]
[FONT=Helvetica Neue]        set [COLOR=#4f8f00]xmldata[/COLOR] to [COLOR=#4f8f00]xmldata[/COLOR] & "<equalizerON>" & [COLOR=#4f8f00]equalizer_state[/COLOR] & "</equalizerON>"[/FONT]
[FONT=Helvetica Neue]        set [COLOR=#4f8f00]xmldata[/COLOR] to [COLOR=#4f8f00]xmldata[/COLOR] & "<album>" & [COLOR=#4f8f00]current_album[/COLOR] & "</album>"[/FONT]
[FONT=Helvetica Neue]        set [COLOR=#4f8f00]xmldata[/COLOR] to [COLOR=#4f8f00]xmldata[/COLOR] & "<artist>" & [COLOR=#4f8f00]current_artist[/COLOR] & "</artist>"[/FONT]
[FONT=Helvetica Neue]        set [COLOR=#4f8f00]xmldata[/COLOR] to [COLOR=#4f8f00]xmldata[/COLOR] & "<title>" & [COLOR=#4f8f00]current_track[/COLOR] & "</track>"[/FONT]
[COLOR=#4F8F00][FONT=Helvetica Neue][COLOR=#000000]        my [/COLOR]writetofile[COLOR=#000000]([/COLOR]xmldata[COLOR=#000000], [/COLOR]filepath[COLOR=#000000])[/COLOR][/FONT][/COLOR]
[FONT=Helvetica Neue]    else[/FONT]
[FONT=Helvetica Neue]        set [COLOR=#4f8f00]xmldata[/COLOR] to [COLOR=#4f8f00]xmldata[/COLOR] & "<iTunes>OFF</iTunes>"[/FONT]
[COLOR=#4F8F00][FONT=Helvetica Neue][COLOR=#000000]        my [/COLOR]writetofile[COLOR=#000000]([/COLOR]xmldata[COLOR=#000000], [/COLOR]filepath[COLOR=#000000])[/COLOR][/FONT][/COLOR]
[FONT=Helvetica Neue]    end if[/FONT]
[FONT=Helvetica Neue]end [COLOR=#0433ff]run[/COLOR][/FONT]
[FONT=Helvetica Neue]
[/FONT]
[COLOR=#4F8F00][FONT=Helvetica Neue][COLOR=#000000]on [/COLOR]xmlheader[COLOR=#000000]()[/COLOR][/FONT][/COLOR]
[FONT=Helvetica Neue]    return "<?xml version=\"1.0\" encoding=\"utf-8\"?>"[/FONT]
[COLOR=#4F8F00][FONT=Helvetica Neue][COLOR=#000000]end [/COLOR]xmlheader[/FONT][/COLOR]
[FONT=Helvetica Neue]
[/FONT]
[FONT=Helvetica Neue]
[/FONT]
[COLOR=#4F8F00][FONT=Helvetica Neue][COLOR=#000000]on [/COLOR]writetofile[COLOR=#000000]([/COLOR]cont[COLOR=#000000], [/COLOR]filepath[COLOR=#000000])[/COLOR][/FONT][/COLOR]
[FONT=Helvetica Neue]    try[/FONT]
[COLOR=#012FBE][FONT=Helvetica Neue][COLOR=#000000]        set [/COLOR][COLOR=#4f8f00]openfile[/COLOR][COLOR=#000000] to [/COLOR]open for access[COLOR=#4f8f00]filepath[/COLOR][COLOR=#000000] with [/COLOR]write permission[/FONT][/COLOR]
[FONT=Helvetica Neue]        [COLOR=#012fbe]set eof[/COLOR] of [COLOR=#4f8f00]openfile[/COLOR] [COLOR=#012fbe]to[/COLOR] 0[/FONT]
[COLOR=#012FBE][FONT=Helvetica Neue][COLOR=#000000]        set [/COLOR][COLOR=#4f8f00]BOM_UTF8[/COLOR][COLOR=#000000] to (([/COLOR]ASCII character[COLOR=#000000] 239) & ([/COLOR]ASCII character[COLOR=#000000] 187) & ([/COLOR]ASCII character[COLOR=#000000] 191))[/COLOR][/FONT][/COLOR]
[COLOR=#4F8F00][FONT=Helvetica Neue][COLOR=#012fbe]write[/COLOR]BOM_UTF8[COLOR=#012fbe]to[/COLOR]openfile[/FONT][/COLOR]
[FONT=Helvetica Neue]        [COLOR=#012fbe]write[/COLOR] [COLOR=#4f8f00]cont[/COLOR] [COLOR=#012fbe]to[/COLOR] [COLOR=#4f8f00]openfile[/COLOR] [COLOR=#012fbe]as[/COLOR] «[COLOR=#0433ff]class[/COLOR] utf8»[/FONT]
[COLOR=#012FBE][FONT=Helvetica Neue]close access[COLOR=#4f8f00]openfile[/COLOR][/FONT][/COLOR]
[FONT=Helvetica Neue]        return [COLOR=#812fdc]true[/COLOR][/FONT]
[FONT=Helvetica Neue]    on error[/FONT]
[FONT=Helvetica Neue]        try[/FONT]
[COLOR=#012FBE][FONT=Helvetica Neue]close access[COLOR=#4f8f00]openfile[/COLOR][/FONT][/COLOR]
[FONT=Helvetica Neue]        end try[/FONT]
[FONT=Helvetica Neue]        return [COLOR=#812fdc]false[/COLOR][/FONT]
[FONT=Helvetica Neue]    end try[/FONT]
[COLOR=#4F8F00][FONT=Helvetica Neue][COLOR=#000000]end [/COLOR]writetofile[/FONT][/COLOR]
 
current track ist ein track-"Objekt"...das kannst Du nicht in einen String umwandeln. Versuch's stattdessen mit name of the current track
 
:clap:
So einfach kann die Lösung sein......
Hast du vielleicht noch eine Idee, wie ich das Script umgestalten kann, um keine Fehlermeldung der Variablen current_album, current_artist und current_track zu bekommen, wenn iTunes gestoppt ist???
Denn dann werden die Variablen nicht befüllt.

Vielen Dank schonmal
 
Du musst vorher den player state abfragen:

Code:
if player state is not stoppen then
-- Werte zuweisen
else
-- "" zuweisen
end if
 
Hallo,

wie aktualisierst Du das XML immer?

Vielleicht kennst Du Tune•Instructor: http://tune-instructor.de/de/

Das Ding läuft als Dienst und observiert alle iTunes-Nachrichten live.

Öfters schon wurde ich von Anwendern angeschrieben, die genau Dein Vorhaben als Einstelloption wünschen.
Derweil biete ich das nicht offiziell an, aber ich habe es bereits eingebaut.

D.h. bei jedem Titelwechsel werden die Informationen immer live in ein XML geschrieben.
Du müsstest mir einfach den Pfad nennen und ein Beispiel Deiner XML-Datei senden.
Dann kann ich Dir, insofern Du das willst, auch so eine individuelle Version zukommen lassen.

Nur so als Info…

Viele Grüße
 
Morgen,

Danke für die Info, aber die Aktualisierung stellt kein Problem dar. Die Aktualisierung löst das Applesript selber welches ich über den Apache des Minis mittels http über meinen Server starte und anschließend gleich die XML parse.

Aber ich werde mir trotzdem mal Tune instructor ansehen.
 
Zurück
Oben Unten