Can I have a Script that can run multiple Terminal scripts in varied folders?

Hi! I was wondering if it was possible to create either a Terminal Script or an Apple Script that is capable of running several Terminal Scripts in differing consoles. Here's the scenario if that would help make things less confusing:


I have several server scripts. I would like to use one script that I can open that will launch all the java scripts in Terminal in their appropriate windows. What I want is to be able to launch one Script, and that will launch the Servers in varying folders.


Please let me know if it is possible to do this. Thanks!

MacBook Pro, OS X Mountain Lion (10.8.4), Technology

Posted on Aug 12, 2013 12:20 PM

Reply
8 replies

Aug 12, 2013 12:31 PM in response to e_bear

Sure. There are multiple ways to do this.

A simple cheap approach is to name the shell script something.command for all the shell scripts that kick off each specific server script. That is to say, if the script file ends with .command, when you double click on it or use the shell 'open' command, it will open a new Terminal window.


Each .command file would invoke your server script


Then you have a master script with something like:


#!/usr/bin/env bash


open first.command &

open second.command &

open third.command &

open forth.command &


etc...


Of course each of the shell scripts should have the execution bit set


chmod +x master.sh

chmod +x *.command


You can most likely do this from Applescript or Automator using a different approach that tells the Terminal to run your server script

Aug 12, 2013 4:10 PM in response to e_bear

the .command files would need to be shell scripts.


The master.sh file with the 'open' commands that I show is a shell script, however, it should be possible to use Applescript or Automator to invoke the .command files. Or have the master.sh shell script I should be invoked via Applescript or Automator.


I am NOT an Applescript nor Automator expert, so I did not try to give instructions for those.


NOTE: It maybe possible to do everything you want via Applescript or Automator, but that is not my skill set.

Aug 12, 2013 4:49 PM in response to e_bear

#! /usr/bin/bash


open /path/to/file &

#...etc, as Bob laid out


You can compile the script using textedit. Save the file as "fileopen" , for example, as a plain text document in Textedit. Save it to a particular location. If you save it to your documents folder, and the name is "fileopen.txt" you would run the commands below to compile the script into a unix executible file:


cd ~/Documents

mv fileopen.txt fileopen

chmod +x ./fileopen



Anytime you open terminal and type in ~/documents/fileopen, the script would execute. To make it easier, you may want to save the script in /usr/bin/ . This would allow you to simply type "fileopen" and terminal will execute the command, since /usr/bin/ is a shell path by default.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Can I have a Script that can run multiple Terminal scripts in varied folders?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.