Neues Terminal-Register öffnen und Skript ausführen

19126
ThomasReggi

Ich muss zwei Javascript-Scripts zusammenführen, damit ich mit einem Befehl eine neue Terminal-Registerkarte öffnen und ein Skript wie echo hellodiese neue Registerkarte ausführen kann .

Dieser öffnet eine neue Terminal-Registerkarte.

osascript -e 'tell application "Terminal" to activate' -e 'tell application "System Events" to tell process "Terminal" to keystroke "t" using command down' 

Dieses öffnet ein neues Fenster und läuft echo hello

osascript -e 'tell app "Terminal" do script "echo hello" end tell' 
5

5 Antworten auf die Frage

7
user495470

Ich kenne keinen besseren Weg, um eine neue Registerkarte zu erstellen, aber Sie können einen Befehl in der vordersten Registerkarte oder im Fenster mit ausführen do script "" in window 1.

tell application "Terminal" activate tell application "System Events" to keystroke "t" using command down repeat while contents of selected tab of window 1 starts with linefeed delay 0.01 end repeat do script "echo a" in window 1 end tell 
Wissen Sie, ob es neben dem Befehl do script noch einen anderen Weg gibt? Sie möchten den Befehl mit Hyper Terminal ausführen, das diese Syntax nicht unterstützt Borat.sagdiyev vor 6 Jahren 0
1
bbezanson

Hier ist ein Ausschnitt, den wir verwenden. Ich würde vorschlagen:

  • Fügen Sie dies in eine Funktion ein, wie eine "Registerkarte".
  • Verwenden Sie für den Befehl eine Variable, die Sie in die Funktion übergeben

    osascript  -e "tell application \"Terminal\" to activate" \ -e "tell application \"System Events\" to keystroke \"t\" using " \ -e "do script \"echo hello\" in front window" \ -e "end tell" > /dev/null 
1
Raheel

Der einfachste Weg ist die Verwendung von "ttab"

https://www.npmjs.com/package/ttab

Führen Sie ttab 'ls -la'hier einfach ls -laden Befehl aus, den ich in einem neuen Tab ausführen möchte.

Hinweis: ttabBenötigt die Installation von NPM

0
adayzdone

Try

osascript -e 'tell application "Terminal" to activate' -e 'tell application "System Events" to tell process "Terminal" to keystroke "t" using command down' -e 'tell application "Terminal" to do script "echo hello" in tab 2 of window 1' 
0
Hauke Hell

Ähnlich wie bei adayzdone, aber etwas anders:

osascript -e 'tell application "Terminal" to activate' \ -e 'tell application "System Events" to keystroke "t" using ' \ -e 'tell application "Terminal" to do script "echo hello" in front window'