3

I have 10 script files and each file contain up to 100 commands ( each command take 1 min ). At the moment it saves me time and I click only one file to execute 100 commands but what I want is another script file which execute 10 script files sequentially instead of me waiting for each to finish and then executing the second script file by clicking it.

jww
  • 97,681
  • 90
  • 411
  • 885
Dr. Mian
  • 3,334
  • 10
  • 45
  • 69

2 Answers2

3

You just call each script as you would before, but seperate them with a semicolon ;

After each script finishes execution, bash will start executing the next script.

In the terminal:

./scriptsrc/script_1; ./scriptsrc/script_2; ./scriptsrc/script_n;

If you need more guidance check this question out, its fairly similar.

EDIT: If you want to run multiple scripts from one other script this can be accomplished by adding the shebang line to tell the kernel the file is executable and then just listing what scripts you want:

#!/bin/bash

./scriptsrc/script_1 
./scriptsrc/script_2
./scriptsrc/script_n

echo "script execution complete"
Community
  • 1
  • 1
Lyuben Todorov
  • 13,987
  • 5
  • 50
  • 69
  • Thanks, it worked and I can run multiple scripts by typing its name one after the other at command prompt (terminal) but does it mean that we cannot run script files from a script file? – Dr. Mian Jul 14 '12 at 00:53
  • @Asbat you can indeed run them from a script file, you just need to ad the shebang line ( `#!/bin/bash` ) and then call each script on a seperate line without the `;` please look at the edit. – Lyuben Todorov Jul 14 '12 at 00:57
  • I have no issue running the scripts in the terminal but once I try to run them in a separate script I get a "Permissions Denied issue" any reason? I dont have an sudo settings on the script prior. – emarel Feb 01 '16 at 19:08
0
set a to alias POSIX file "/Users/Firebird/Documents/script1.scpt"
set b to alias POSIX file "/Users/Firebird/Documents/script2.scpt"
set c to alias POSIX file "/Users/Firebird/Documents/script3.scpt"

set theScriptFiles to {a, b, c}
repeat with scriptFile in theScriptFiles
    run script scriptFile
end repeat

The last script on the list didn't run the first couple of times when I was testing for an unknown reason, but after I ran

set myList to {"Hello", "Goodbye", "I must be going"}
repeat with theItem in myList
    say theItem
end repeat

it worked!

To make sure all the scripts ran I tell Texteditor to open a file for each corresponding script:

tell application "Finder" to open "Macintosh:Users:Firebird:Documents:ranscript1.rtf"

This thread is really good too from MacScripter http://macscripter.net/viewtopic.php?id=44260

S.Doe_Dude
  • 151
  • 1
  • 5