iTerm2: So erhalten Sie die Ausgabe eines Shell-Befehls mit applescript

1030
Lars Bilke

Ich möchte, dass die Ausgabe eines Shell-Befehls durch iTerm2-Applescript in eine Applescript-Variable ausgeführt wird. Ich habe folgendes versucht, aber es funktioniert nicht:

tell application "iTerm" activate try set _session to current session of current terminal on error say "Error" end try tell _session set Directory to write text "pwd" get Directory set Directory to exec command "pwd" get Directory end tell end tell 

Danke für Ihre Hilfe!

3

1 Antwort auf die Frage

0
rachit

du könntest es versuchen.

tell application "iTerm" activate try set _session to current session of current tab of current window on error say "Error" end try tell _session write text "pwd" set terminalContent to text of _session end tell end tell set output to paragraph -2 of trim(true, terminalContent)  on trim(theseCharacters, someText) if class of someText is text and length of someText > 0 then -- default values (all whitespace) if theseCharacters is true then ¬ set theseCharacters to {" ", tab, ASCII character 10, return, ASCII character 0}  repeat until first character of someText is not in theseCharacters set someText to text 2 thru -1 of someText end repeat  repeat until last character of someText is not in theseCharacters set someText to text 1 thru -2 of someText end repeat end if  return someText end trim 

Dies gibt die Ausgabe des Befehls zurück, den Sie write textin Zeile 9 des obigen Codes angeben .