Abra la nueva pestaña en ITERM y ejecute comando allí
Pregunta
He encontrado la forma de abrir una nueva pestaña en iTerm
:
newtabi()
{
osascript -e 'tell application "iTerm" to activate' -e 'tell application "System Events" to tell process "iTerm" to keystroke "t" using command down'
}
y quiero ejecutar algunos comandos en nueva pestaña.Deja que sea simple comando pwd
.¿Cómo hacerlo?
si corro ...
newtabi && pwd
La nueva pestaña se abre como se esperaba, pero el comando pwd
se ejecuta, no se ejecuta en una pestaña nueva, sino en la anterior, donde escribí newtabi && pwd
Yo uso zsh
.Mi sistema operativo es OS X 10.8.5
Solución
Utilice tell session -1 of current terminal to write text "pwd"
:
activate application "iTerm"
tell application "System Events" to keystroke "t" using command down
tell application "iTerm" to tell session -1 of current terminal to write text "pwd"
Otros consejos
osascript \
-e 'tell application "iTerm" to activate' \
-e 'tell application "System Events" to tell process "iTerm" to keystroke "t" using command down' \
-e 'tell application "System Events" to tell process "iTerm" to keystroke "ls"' \
-e 'tell application "System Events" to tell process "iTerm" to key code 52'
AS de al menos MacOS Mojave, ITERM 3.2.8, si ejecuta:
$ open -a iTerm .
lo agregará como una pestaña a la ventana actual.
No pude obtener la respuesta aceptada para trabajar.También quería pasar múltiples comandos.Esto es con lo que acompañé.
newtabi(){
osascript \
-e 'tell application "iTerm2" to tell current window to set newWindow to (create tab with default profile)'\
-e "tell application \"iTerm2\" to tell current session of newWindow to write text \"${@}\""
}
Ejemplo de uso
newtabi pwd
newtabi 'cd ~/ && pwd'
newtabi 'echo \"Hello New Tab\"'
Para acciones más complejas, recomendaría romper los comandos.
code_folder="/path/to/code"
alias project="cd ${code_folder}/my-project/foo && yarn run start"
entonces, newtabi project