• Apfeltalk ändert einen Teil seiner Allgemeinen Geschäftsbedingungen (AGB), das Löschen von Useraccounts betreffend.
    Näheres könnt Ihr hier nachlesen: AGB-Änderung
  • Viele hassen ihn, manche schwören auf ihn, wir aber möchten unbedingt sehen, welche Bilder Ihr vor Eurem geistigen Auge bzw. vor der Linse Eures iPhone oder iPad sehen könnt, wenn Ihr dieses Wort hört oder lest. Macht mit und beteiligt Euch an unserem Frühjahrsputz ---> Klick

[AppleScript] Prüfen, ob iTunes auf entfernter Maschine läuft

Kampfgnom

Granny Smith
Registriert
11.06.07
Beiträge
14
Hi,

Man kann ja iTunes auf entfernten Mac OS X Rechnern steuern:
Code:
tell application "iTunes" of machine "eppc://192.168.1.200" to next track
Nun würde ich gerne überprüfen,

Code:
ob das entfernte iTunes läuft
    dann das entfernte iTunes steuern
wenn nein
   dann das lokale iTunes steuern.
Meine ersten Ansätze:

Code:
on getHost()
    tell application "System Events" of machine "eppc://192.168.1.200" to set isRunning to (name of processes) contains "iTunes"
    if isRunning then
        return "eppc://192.168.1.200"
    else
        return "eppc://192.168.1.201"
    end if
end getHost
try
        set theHost to getHost()
        tell application "iTunes" of machine theHost to playpause
end try

Allerdings funktioniert das nicht, weil wenn hinter "of machine" eine Variable und kein String-Literal folgt, denkt er dass playpause eine Variable wäre o_O :mad:

Komme mit Applescript nicht wirklich klar. Es ist einfach nicht logisch.

Code:
#funktioniert:
tell application "iTunes" of machine "eppc://192.168.1.200" to playpause

#funktioniert nicht!
set theHost to "eppc://192.168.1.200"
tell application "iTunes" of machine theHost to playpause
:mad:

Und dann ist auch noch die Undo-Funktion vom Scripteditor verbuggt... alter schwede

Danke :)
 

sedna

Galloway Pepping
Registriert
22.10.08
Beiträge
1.359
Hallo Kampfgnom! :)

Hihi! Manchmal kann man wirklich verzweifeln. Kopf hoch!

Code:
set theHost to "eppc://192.168.1.200"
using terms from application "iTunes"
    tell application "iTunes" of machine theHost to playpause
end using terms from
Mir ist übrigens noch gar nicht aufgefallen, daß die Undo Funktion buggy ist.
Was stimmt denn da nicht?

Sedna
 

Kampfgnom

Granny Smith
Registriert
11.06.07
Beiträge
14
EDIT: Siehe unten...
################################################
Ich verstehe zwar nicht was dieses Konstrukt soll, will es aber auch lieber nicht wissen. Hinterher mag ich noch Apple-Script *schauder*
Auf jeden Fall danke, es funktioniert nun:
Code:
on checkProcess()
    tell application "System Events" of machine "eppc://192.168.1.200"
        set isRunning to ((application processes whose (name is equal to "iTunes")) count)
    end tell
    if isRunning is greater than 0 then
        return true
    else
        return false
    end if
end checkProcess

on getHost()
    if checkProcess() then
        return "eppc://192.168.1.200"
    else
        return "eppc://192.168.1.201"
    end if
end getHost

set theHost to getHost()
using terms from application "iTunes"
    tell application "iTunes" of machine theHost to playpause
end using terms from
Etwas umständlich, aber hey es läuft...

Was verbuggt ist an der Undo-Funktion:
Nachdem ich ein paar mal Apfel-Z gedrückt habe kommt das hier dabei raus:
Code:
on checkProcess()
    tell application "System Evenachine "eppc://192.168.1.200"
        set isRunning to ((application processes whose (name is equal to "iTunes")) count)
    end tell
    if isRunning is greater than 0 then
        return tru//192.168.1.200"e
    else
        return f//192.168.1.201"alse
    end if
end checkProcess

on getHost()
    if ceppc://192.168.1.201"
    end if
end g from application "iTunes"
    tell application "iTuneachine theHost to playpause
end using terms from
Manchmal passiert auch einfach nichts, was meistens besser ist, weil Redo funktioniert bei mir auch nicht. Hab schon lange nicht mehr neugestartet und auch den Scripteditor seit ein paar Tagen am laufen. Kann also nicht sagen, ob das ganze reproduzierbar ist.

Danke nochmal
################################################
EDIT:
Hm Applescript scheint nicht deterministisch zu sein. Das Script funktioniert eine zeitlang (5 Minuten). Jetzt sagt er mir:
System Events got an error: Cannot find process on host

Was mach ich denn nun?
 

Kampfgnom

Granny Smith
Registriert
11.06.07
Beiträge
14
Ich Doppelposte mal um die Übersicht zu erhalten. Es funktioniert nun endgültig (meine Änderungen in Rot):
Code:
[COLOR=Red]set myHost to "eppc://192.168.1.200"[/COLOR]
on checkProcess()
    try
        tell application "System Events" of machine [COLOR=Red]myHost[/COLOR]
            set isRunning to ((application processes whose (name is equal to "iTunes")) count)
        end tell
        if isRunning is greater than 0 then
            return true
        else
            return false
        end if
    on error
        return false
    end try
end checkProcess

on getHost()
    if checkProcess() then
        return "eppc://192.168.1.200"
    else
        return "eppc://192.168.1.201"
    end if
end getHost

set theHost to getHost()
using terms from application "iTunes"
    tell application "iTunes" of machine theHost to playpause
end using terms from
Warum funktioniert das jetzt und vorher nicht? Semantisch ist es genau das gleiche o_O