Terminalbefehl als App / Script umsetzen

Gib mal als Zeile 3 ein:
Code:
display dialog result as string
Dann siehst Du die Antwort die zurückkommt.
 
  • Gefällt mir
Reaktionen: Maddeen
Also so?

Code:
try
    do shell script "/usr/bin/ssh root@10.20.0.1 virsh start Windows_10q35_5_own_vBIOS"
    display dialog result as string
    if result is "Domain Windows_10q35_5_own_vBIOS started" then
        display notification "VM started successfully" with title "Gaming VM"
    else
        display notification "VM couldn't started" with title "Gaming VM"
    end if
on error
    display notification "Script Error" with title "Gaming VM"
end try
 
Hat geklappt - VM läuft auch!
Allerdings verstehe ich nicht, warum er die Fehlermeldung bringt. Für mich sieht das Result genau so aus, wie ich es eingegeben habe

Bildschirmfoto 2021-03-27 um 11.22.15.png


Der Editor gibt im Bereich ANTWORTEN folgendes aus
AppleScript:
tell current application
    do shell script "/usr/bin/ssh root@10.20.0.1 virsh start Windows_10q35_5_own_vBIOS"
        --> "Domain Windows_10q35_5_own_vBIOS started
"
end tell
tell application "Script Editor"
    display dialog "Domain Windows_10q35_5_own_vBIOS started
"
        --> {button returned:"OK"}
    display notification "VM couldn't started" with title "Gaming VM"
end tell

Im Bereich EVENTS steht folgendes:
AppleScript:
tell current application
    do shell script "/usr/bin/ssh root@10.20.0.1 virsh start Windows_10q35_5_own_vBIOS"
end tell
tell application "Script Editor"
    display dialog "Domain Windows_10q35_5_own_vBIOS started
"
    display notification "VM couldn't started" with title "Gaming VM"
end tell
 
Da ist wieder das Problem mit dem Zeilenumbruch.
Mach mal result contains statt =

if result contains "Domain Windows_10q35_5_own_vBIOS started" then
 
  • Gefällt mir
Reaktionen: Maddeen
Leider nein @oneOeight
Script wie folgt angepasst:
AppleScript:
try
    do shell script "/usr/bin/ssh root@10.20.0.1 virsh start Windows_10q35_5_own_vBIOS"
    display dialog result as string
    if result contains "Domain Windows_10q35_5_own_vBIOS started" then
        display notification "VM started successfully" with title "Gaming VM"
    else
        display notification "VM couldn't started" with title "Gaming VM"
    end if
on error
    display notification "Script Error" with title "Gaming VM"
end try

EVENTS
AppleScript:
tell current application
    do shell script "/usr/bin/ssh root@10.20.0.1 virsh start Windows_10q35_5_own_vBIOS"
end tell
tell application "Script Editor"
    display dialog "Domain Windows_10q35_5_own_vBIOS started
"
    display notification "VM couldn't started" with title "Gaming VM"
end tell

ANTWORTEN
AppleScript:
tell current application
    do shell script "/usr/bin/ssh root@10.20.0.1 virsh start Windows_10q35_5_own_vBIOS"
        --> "Domain Windows_10q35_5_own_vBIOS started
"
end tell
tell application "Script Editor"
    display dialog "Domain Windows_10q35_5_own_vBIOS started
"
        --> {button returned:"OK"}
    display notification "VM couldn't started" with title "Gaming VM"
end tell
 
Dann probier mal Varianten.
Code:
if result is "Domain Windows_10q35_5_own_vBIOS started
" then

Code:
if result is "Domain Windows_10q35_5_own_vBIOS started\n" then
 
Leider auch ohne Erfolg.
Die letzte Variante scheint er auch nicht zu akzeptieren, weil er es sofort nach dem Ausführen so anpasst, wie deine erste Variante :)
 
\n steht auch für newline, also neue Zeile.
Vielleicht ist es auch \r also Carriage return.
Also probier mal \r.

Sonst vereinfachen mit
If result contains "started"
 
Du musst
Code:
display dialog result as string
wieder rausnehmen sonst ist result danach etwas anderes. Danach oneOeights Vorschlag nochmal versuchen.
 
  • Gefällt mir
Reaktionen: mausfang und Maddeen
Ahhh .. jetzt gehts. Vielen Dank an euch zwei!!!
Die Lösung war also in der Tat den display dialog wieder zu entfernen und dann mit "result contains" zu arbeiten!!
Screenshot und finales Script habe ich für die Nachwelt jetzt noch mal angehangen.

Generell noch eine Frage bzgl. einer "Gold-Rand-Lösung".
Weiß jemand von euch ggf. auch, wie ich es hinbekomme, dass die Notifications nicht den Scripteditor als "Absender" haben sondern den Namen der "App".
Oder geht das dann wirklich nur, wenn ich eine native App daraus mache?

Bildschirmfoto 2021-03-27 um 14.44.29.png


AppleScript:
try
    do shell script "/usr/bin/ssh root@10.20.0.1 virsh start Windows_10q35_5_own_vBIOS"
    if result contains "Domain Windows_10q35_5_own_vBIOS started" then
        display notification "VM started successfully" with title "Gaming VM"
    else
        display notification "VM couldn't started" with title "Gaming VM"
    end if
on error
    display notification "Script Error" with title "Gaming VM"
end try
 
  • Gefällt mir
Reaktionen: Atalantia
Probier doch aus und speicher als Programm.
 
  • Gefällt mir
Reaktionen: mausfang
Das hab ich ja schon. Daher die "Gänsefüßchen" bei "App" :)
Vom generellen Aufbau (Paketinhalt) sieht es auch nach einer vollwertigen App aus.

Ich guck mal, ob ich sonst noch Infos finden kann :)

Bildschirmfoto 2021-03-27 um 15.16.35.png
 
Zuletzt bearbeitet:
Info.plist bearbeiten
 
  • Gefällt mir
Reaktionen: Maddeen
Ok... ich hatte eigentlich das standard icns mit meiner File überschrieben. Warum auch immer, mag er das wohl nicht.
Jetzt habe ich die icns umbenannt und die plist entsprechend angepasst - läuft :)

Danke dir noch mal und schönes Wochenende.

P.S
Sofern du kannst / magst, würde ich mich über einen Link freuen, wo ich erkennen kann, wie man unterschiedliche Error-Messages auf Basis der Error-Results ausgeben kann :)
Also ähnlich der "if result contains"
sowas wie
  • if error contains "domain already active"
  • display notification "Your VM is already started"
  • if error conatins "domain not found"
  • display notification "Your VM can not be found"
Aktuell habe ich ja nur ein "on error" - das kann aber natürlich mehrere Ursachen haben.

Bildschirmfoto 2021-03-27 um 16.26.29.png
 
Da musst du zwischen dem return code von do shell script und dem result unterscheiden.
On error triggert wohl nur wenn do shell script nicht richtig beendet.
Du musst also result auswerten.
D.h. if then else für alle Fälle.
 
  • Gefällt mir
Reaktionen: Maddeen
Code:
on error erstrg
speichert die Fehlermeldung in der Variablen erstrg
 
  • Gefällt mir
Reaktionen: Maddeen
Du kannst auch mit
Code:
set r to do shell script "/usr/bin/ssh root@10.20.0.1 virsh start Windows_10q35_5_own_vBIOS"
das result vom shell script in der variablen r speichern und später mit ifs auswerten.
 
  • Gefällt mir
Reaktionen: Maddeen
Danke... ich versuch mich mal reinzufuxxen :) Vielleicht bekomme ich es auch mit swift in eine saubere app, wo der User den Namen seiner VM direkt eingeben und speichern kann.
Bzw. von mehreren VMs ... hab mir gerade bei udemy nen angeblich guten Kurs geschossen... we'll see.

Schönes WE
 
Swift ist nicht schwierig aber das Cocoa Framework ist kompliziert.
 
  • Gefällt mir
Reaktionen: mausfang
Mach mal nach dem do Shell ein „log result“ ...
 
Zurück
Oben Unten