JZ.
JZ.

Reputation: 21877

Is there a way to open a series of new terminal window, and run commands in a single script?

Every day I do the following commands:

[0] Start terminal

  1. Open window -> memcached
  2. Open window -> redis-server
  3. Open window -> memcached
  4. Open window -> devo
  5. Open window -> cd /some/path
  6. /some/path$ -> rails s --port=3002
  7. Open window -> cd /other/path
  8. /other/path$ -> rails s --port=3000

Can these steps be accomplished in a single script? I'm losing my mind doing these steps every time I restart my system

Upvotes: 4

Views: 3329

Answers (2)

David W.
David W.

Reputation: 107040

Well, if you don't mind using xterm as your terminal, you can do this in your shell scripts:

xterm -e $command

You can also use the open command which is unique to the Mac:

open -a /Applications/Utilities/Terminal.app $command  #Full pathname to $command!

For example:

open -a /Applications/Utilities/Terminal.app /usr/bin/vim

Works.

You can also use a shell script:

open -a /Applications/Utilities/Terminal.app /home/david/foo.sh

What I haven't figured out is how to open a command that requires a command line parameter. If you have to do that, you'll have to stick to xterm.

Upvotes: 0

Kassym Dorsel
Kassym Dorsel

Reputation: 4843

Create an applescript. You will just need to run the applescript and it'll do all that for you :

tell application "Terminal"
    activate
    do script "memcached" in window 1
    do script "redis-server" -- Each do script opens a new window
    do script "memcached"
    do script "devo"
    do script "cd "
    do script "rails s --port=3002" in window 1 -- does script in last opened window
    do script "cd "
    do script "rails s --port=3000" in window 1 -- does script in last opened window
end tell

Save it as an Application so you can double click it to run it. You could also assign it to start on system start or even to a shortcut with a necessary third party program.

Upvotes: 10

Related Questions