Runing another script within the script

Hiyas

I got this scenario…
I had write several scrpits installers for various applications, e.g. photoshop, illustrator etc…
Basically they are just to open up a img file (pre-made) and copy all the files there to the HD.
Each application have their own applescript installers.

And now i wrote a Master script which will run these individual application script one by one.

The problem to this is that the master script won’t wait for the application script to finish running before it continues to run another script.

E.g. I run master script which then run the photoshop script, the photoshop script then starts to run, however the master script is still running so it continues on with the codes and run illustrator script (which the photoshop script is still running) and similiarly without waiting those photoshop and illustrator to finish, it gets onto the third application script.

Which eventually creates a huge mess.

Is there a way to set the master script to somehow continue on after 1 script had finished running??

Help is much appreciated

Winston

Winston,

The only way I know how to get the currently running Applications
is by using Akua Sweets “all processes”. Maybe someone knows
of another way to list this - Just keep listing the open applications
until the installer script name no longer shows up in the list.

You can get Akua Sweets here free for non-commercial use:
http://osaxen.com/modules.php?op=modload&name=Downloads&file=index&req=getit&lid=62

--launch your installer script then...

set theActiveApps to all processes
repeat until theActiveApps does not contain "TheNameOfYourInstallerScriptAsItAppearsInTheAppSwitcher"
	set theActiveApps to all processes
end repeat

Best,

Thanx for that info… i will try that right away.

just got another little question.

Besides running all the application script in one go, i had also built the master script so that it can install scripts individually if they don’t need or want to run all the installers.

A dialog box will come up with selection prompt asking the user what they want to do before any running the installers. Options all:

  1. Install All (which creates the problem mentioned above)
  2. Install photoshop only (which only run the photoshop script)
  3. Install illustrator only (only run illustrator script)
    … 4) Install Quark 5) Install blah blah blah 6) … etc etc…

Besides choosing the `Install All’ option, is there a way to make the master script so that after installing individual applications (e.g. photoshop only) it will return to this dialog box instead of quit the script.

E.g. if I only want to install photoshop and quark, after picking the install photoshop option, the master script quits and i need to re-run the master script and this time pick on quark.

Help is really really appreciated. I am a newbie who is now finding all the joy and tears about applescript.

Thanx heaps. u guys are great!!!

Winston

Winston,

It’s pretty late, and I sometimes write useless stuff when I’m tired but this seems to work. It should send the user back to the dialog - and as an added bonus keep track of which apps have been installed and omit them from future dialogs.

(*set up a few properties, at the end of the master script
check to see if all 3 are done, if not run thru the script again.*)
property PshopDone : ""
property QuarkDone : ""

set PshopDone of me to false --reset the properties to false
set QuarkDone of me to false

--when the script runs it hits this handler first and performs it
MasterScript() of me

--now that the master installer has run check to see if everything has been installed 
if PshopDone of me = false or QuarkDone of me = false then --if either is not installed run it again
	MasterScript() of me
end if


--wrap your master installer with this handler
on MasterScript()
	tell application "Finder"
		activate
		if QuarkDone of me = false and PshopDone of me = false then
			display dialog "Choose the apps you want to install" buttons {"Quark", "Photoshop", "All"} default button 3 with icon note
			set InstallChoice to the button returned of the result
		else if QuarkDone of me = false and PshopDone of me = true then
			display dialog "You can still install Quark" buttons {"Quark", "Quit"} default button 2 with icon note
			set InstallChoice to the button returned of the result
		else if QuarkDone of me = true and PshopDone of me = false then
			display dialog "You can still install Photoshop" buttons {"Photoshop", "Quit"} default button 2 with icon note
			set InstallChoice to the button returned of the result
		end if
	end tell
	
	
	if InstallChoice = "Quark" then
		set QuarkDone of me to true
		--run the Quark installer
	else if InstallChoice = "Photoshop" then
		set PshopDone of me to true
		--run the Pshop installer
	else if InstallChoice = "All" then
		set PshopDone of me to true
		set QuarkDone of me to true
		--run the Quark installer
		--run the Pshop installer
	else if InstallChoice = "Quit" then --the user is quitting
		return
	end if
end MasterScript

This is probably kind of a wordy method to getting it done but it does work.
Also, I am using OS 8.6 Applescript v 1.3.7 here.

Hope this helps,

Instead sending a “run” event to the installer script (eg. “run app theInstaller” or “tell app Finder to open theInstaller”), you can setup a handler, so your master script will wait for a response:
Master Script

whit timeout of 3600 seconds -- give the installer 1 hour to finish its work
   tell app "QuarkInstaller" to beginInstall()
end timeout

QuarkInstaller Script

to beginInstall()
   -- copy files, mount disks or do whatever
   -- the master script is waiting for me ;-)
end beginInstall() -- here the Master will receive a response and will continue running

Perhaps a simple solution is a simple repeat loop:

repeat -- forever
   set x to button returned of display dialog [...]
   if x = "Quark" then dowhatever
   if x = "Quit, please" then exit repeat
end repeat