Open Terminal from shell and execute commands
15,162
Option 1 with xterm (will automatically close the window when completed):
xterm -e "cd /tmp/; watch 'pwd;date'"
Option 2 with MacOS terminal:
osascript -e 'tell application "Terminal" to do script "cd /tmp;pwd"'
Author by
Calebmer
Updated on June 03, 2022Comments
-
Calebmer almost 2 years
I am lazy so I want to write a shell script to open my dev environment. I setup two commands
dev
anddev-startup
. When I rundev /directory/path
it should open a new terminal window at/directory/path
and executedev-startup
.I'm not sure how to open the terminal window at a specific directory and then run a final command to run the tools I need to setup the environment.
I'm running OSX, so maybe AppleScript is the answer?
-
Calebmer almost 9 yearsWith the second command I've found a weird interaction. Whenever I open a new tab it executes the command.
-
volker almost 9 yearsI am sure you can adjust the osascript so it will only do it once.
-
Fernando Wittmann over 5 yearsIs this also possible on iTerm? This command didn't work:
osascript -e 'tell application "iTerm" to do script "cd /tmp;pwd"'
-
volker over 5 years