Ankündigung

Einklappen
Keine Ankündigung bisher.

iTunes Steuerung via ExecBinding

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

    iTunes Steuerung via ExecBinding

    Aloha,

    da ich über openHAB gerne mein iTunes auf meinem MacMini steuern möchte (openHAB & iTunes Server sind beide auf dem MacMini) habe ich mich mit dem Exec-Binding beschäftigt.

    Folgende Items habe ich angelegt (Screenshot befindet sich im Anhang).
    casa.items:
    Code:
    /* iTunes Control */
    Switch Radio_Switch "Radio" <radio>         
    { exec="ON:osascript -e 'tell application \"iTunes\" to play',
    OFF:osascript -e 'tell application \"iTunes\" to stop'" }
    Number Radio_Station "Station" <radio>
    Dimmer Radio_Volume "Volume [%.1f %%]" <speaker_dark>
    casa.sitemap:
    Code:
            Frame label="Info" {
                    Text item=Datum
                    Group item=Weather icon="sun_clouds"
                    Text label="Music" icon="video" {
                            Switch item=Radio_Switch label="Radio" mappings=[ON="On",OFF="Off"]
                            Switch item=Radio_Station label="Kanäle" mappings=[1=1Live, 2=WDR2, 3=Antenne]
                            Slider item=Radio_Volume label="Lautstärke"
                    }
            }
    Wenn ich jetzt iTunes an- oder ausschalten möchte erscheint der Aufruf via osascript brav in den logs:
    Code:
    10:14:13.218 DEBUG o.o.i.r.i.r.ItemResource[:200] - Received HTTP POST request at 'items/Radio_Switch/' with value 'ON'.
    10:14:13.229 INFO  runtime.busevents[:42] - Radio_Switch received command ON
    10:14:13.262 INFO  o.o.b.e.internal.ExecBinding[:131] - executed commandLine 'osascript -e 'tell application "iTunes" to play''
    ...aber es tut sich nix! Wenn ich die Kommandozeile manuell ausführe, dann klappt es einwandfrei!
    Was mache ich falsch?!?!?
    Beste Grüße,
    Manolo
    Angehängte Dateien

    #2
    hmm, warum auch immer muss man wohl manchmal die String[] Signatur von Runtime.getRuntime().exec() verwenden (siehe auch Running AppleScript from Java - Peter Friese).

    Habe einen Quickfix dafür eingecheckt. Sobald der CI-Build durch ist (morgen früh um 2), kannst Du das Item wie folgt notieren:

    Code:
    Switch Radio_Switch "Radio" <radio>         
    { exec="ON:osascript@@-e@@tell application \"iTunes\" to play,
    OFF:osascript@@-e@@tell application \"iTunes\" to stop" }
    damit geht's dann.

    Gruß,

    Thomas E.-E.
    Visualisierung, Rule/Logic-Engine, Integrationsplattform mit openhab (Supportforum)

    Kommentar


      #3
      Sieht zwar nicht sehr hübsch/lesbar aus, aber sollte wohl so gehen ;-)

      Bei mir hatte ich es anders gelöst: Ich habe mir einfach ein itunes.sh Skript erstellt und rufe dieses vom Exec-Binding auf:
      Code:
      exec="ON:/Users/Kai/Scripts/itunes.sh play, OFF:/Users/Kai/Scripts/itunes.sh pause"
      Viele Grüße,
      Kai

      Kommentar


        #4
        So da bin ich wieder, ich war letzte Woche im Urlaub!

        Also ich habe beides ausprobiert (script und den Patch vom nightly build).
        Das sieht dann so aus:

        casa.items:
        Code:
        Switch Radio_Switch "Radio" <radio>
        {
          exec="ON:/Users/macadmin/Desktop/openhab/itunes.sh play,
                OFF:osascript@@-e@@tell application \"iTunes\" to pause"
        }
        Beides funktioniert wunderbar. Danke an euch zwei!
        Ach ja zur Vollständigkeit halber hier das kurze Skript itunes.sh:
        Code:
        #!/bin/bash
        
        #
        # CONTROL iTUNES VIA OSASCRIPT
        #
        ITUNES_CMD=$1
        OPENHAB_LOG="/Users/macadmin/Desktop/openhab/itunes.log"
        
        echo "Starting itunes.sh script with parameter $ITUNES_CMD" >$OPENHAB_LOG
        
        if [ "xxx$ITUNES_CMD" == "xxxplay" ];
        then
                osascript -e 'tell application "iTunes" to play'
        fi
        
        if [ "xxx$ITUNES_CMD" == "xxxpause" ];
        then
                osascript -e 'tell application "iTunes" to pause'
        fi
        
        if [ "xxx$ITUNES_CMD" == "xxxstop" ];
        then
                osascript -e 'tell application "iTunes" to stop'
        fi
        
        if [ "xxx$ITUNES_CMD" == "xxx" ];
        then
                echo "Parameter missing!" >$OPENHAB_LOG
        fi
        Beste Grüße,
        Manolo

        Kommentar


          #5
          schön zu wissen!
          Visualisierung, Rule/Logic-Engine, Integrationsplattform mit openhab (Supportforum)

          Kommentar


            #6
            Hey ... Cool das dies bei dir funktioniert hat... ich bekomme es leider nicht gebacken... Wobei das ganze sehr neu für mich ist, währe es zu viel verlangt, wenn ich dich bitten würde eine Kurze anleitung zu schreiben .... Vielen Dank...

            Kommentar


              #7
              was fehlt Dir über das Posting #4 hinaus?
              Visualisierung, Rule/Logic-Engine, Integrationsplattform mit openhab (Supportforum)

              Kommentar


                #8
                ich schaus mir morgen nochmals in aller ruhe an geb dan gerne bescheid

                Kommentar


                  #9
                  Genau! Steht doch alles oben im Thread.
                  Was hast du denn nicht verstanden?

                  Kommentar


                    #10
                    Habs mir heute nochmals angeschaut ... irgendwie bekomme ich das mit dem script nicht hin .. könntest du mir das file senden ?

                    Kommentar


                      #11
                      Hi,

                      was bekommst du nicht hin mit dem Script?
                      Das Script ist doch im Thread hinterlegt. Einfach copy & paste und als Skript speichern.

                      Du sollst hier ja auch was lernen...!

                      Kommentar


                        #12
                        Habe es so gelöst

                        [INFORMATION]Switch Music "Music" <media> (GR_media, Lights) { exec="ONsascript@@-e@@tell application \"iTunes\" to play,OFFsascript@@-e@@tell application \"iTunes\" to stop" }
                        [/INFORMATION]


                        Danke dir


                        p.s. gibt es noch andere Befehle ?

                        Wie kann ich die lautstärke verändern ?

                        Kommentar


                          #13
                          Hi,

                          also mein Script habe ich noch ein wenig erweitert.

                          Code:
                          #!/bin/bash
                          
                          #
                          # CONTROL iTUNES VIA OSASCRIPT
                          #
                          ITUNES_CMD=$1
                          OPENHAB_LOG="/Users/macadmin/Desktop/openhab/itunes.log"
                          
                          echo "Starting itunes.sh script with parameter $ITUNES_CMD" >$OPENHAB_LOG
                          
                          if [ "xxx$ITUNES_CMD" == "xxx1live" ];
                          then
                          	osascript -e 'tell application "iTunes" to play track "1LIVE, © Westdeutscher Rundfunk Köln"'
                          fi
                          
                          if [ "xxx$ITUNES_CMD" == "xxxwdr2" ];
                          then
                          	osascript -e 'tell application "iTunes" to play track "WDR 2 Rheinland aktuell, © Westdeutscher Rundfunk Köln"'
                          fi
                          
                          if [ "xxx$ITUNES_CMD" == "xxxantenne" ];
                          then
                          	osascript -e 'tell application "iTunes" to play track "Antenne Düsseldorf"'
                          fi
                          
                          if [ "xxx$ITUNES_CMD" == "xxx50s2now" ];
                          then
                          	osascript -e 'tell application "iTunes" to play playlist "50s2now Mix"'
                          fi
                          
                          if [ "xxx$ITUNES_CMD" == "xxxplay" ];
                          then
                          	osascript -e 'tell application "iTunes" to play'
                          fi
                          
                          if [ "xxx$ITUNES_CMD" == "xxxpause" ];
                          then
                          	osascript -e 'tell application "iTunes" to pause'
                          fi
                          
                          if [ "xxx$ITUNES_CMD" == "xxxstop" ];
                          then
                          	osascript -e 'tell application "iTunes" to stop'
                          fi
                          
                          if [ "xxx$ITUNES_CMD" == "xxxvol" ];
                          then
                          	osascript -e 'tell application "iTunes" to set sound volume to 10'
                          fi
                          
                          if [ "xxx$ITUNES_CMD" == "xxxstatus" ];
                          then
                          	osascript -e 'tell application "iTunes" to player state as string'
                          fi
                          
                          if [ "xxx$ITUNES_CMD" == "xxx" ];
                          then
                          	echo "Parameter missing!" >$OPENHAB_LOG
                          fi
                          Am Ende siehst du wie du andere Befehle an iTunes senden kannst. Für eine detaillierte Auflistung kannst du im Applescript Editor die Library aufrufen und dort unter iTunes alle Klassen und Eigenschaften einsehen.
                          gtx, Manolo

                          Kommentar


                            #14
                            Hey Supper ...

                            Muss ich mir mal genau anschauen vielen Dank

                            Kommentar


                              #15
                              Hey wollte es nochmals mit deinem Script versuchen aber irgendwie geht das trotzdem nicht :S

                              [INFORMATION]18:49:15.152 ERROR o.o.b.e.internal.ExecBinding[:150] - couldn't execute commandLine '/Users/server/Desktop/itunes.sh play'
                              java.io.IOException: Cannot run program "/Users/server/Desktop/itunes.sh": error=13, Permission denied
                              at java.lang.ProcessBuilder.start(ProcessBuilder.java :460)
                              Caused by: java.io.IOException: error=13, Permission denied
                              at java.lang.UNIXProcess.forkAndExec(Native Method)[/INFORMATION]

                              Ausgabe aus dem Java :S

                              Kommentar

                              Lädt...
                              X