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"'
Share:
15,162
Calebmer
Author by

Calebmer

Updated on June 03, 2022

Comments

  • Calebmer
    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 and dev-startup. When I run dev /directory/path it should open a new terminal window at /directory/path and execute dev-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
    Calebmer almost 9 years
    With the second command I've found a weird interaction. Whenever I open a new tab it executes the command.
  • volker
    volker almost 9 years
    I am sure you can adjust the osascript so it will only do it once.
  • Fernando Wittmann
    Fernando Wittmann over 5 years
    Is this also possible on iTerm? This command didn't work: osascript -e 'tell application "iTerm" to do script "cd /tmp;pwd"'
  • volker
    volker over 5 years