Running Applications sequentially

Hi guys,

i was trying to run 2 applications that i wrote consecutively, one after another, but facing problems.

The way i did it was using

run application appPath
run application appPath2

but that didn’t work well as after the 1st application ran, it gave me a connection invalid error.

so i tried the suggestions from the forum and tried

tell application “Sytem Events”
open appPath
open appPath2
end tell

but that ran the 2 applications concurrently. Is there a way to run them one after another?

hi thanx,

but, i probably have to explain myself better

The first application is supposed to grab some mails and do some processes on it. So I can’t really predict a delay for it.
The 2nd application is supposed to work on the results of these processes.

as such, I can’t define a constant delay

the keyword run runs scripts, to run an application use launch or activate

What’s about launch the first application, process the things you want and then launch the second app

tell application "app1"
	-- do something
end tell
tell application "app2"
	-- do something
end tell

Presumably these are script applets you’ve written and there’s some good reason why they can’t be amalgamated into one script.

The “connection invalid” error usually comes about when an application disappears or quits while being sent a script command. Your applets will quit as soon as they’ve done their stuff and this may be having some effect on their feedback to the script you’re using to run them. I’ve had some success with this:

launch application appPath
run application appPath

launch application appPath2
run application appPath2

If the applications really are script applets, you could run their code inside your main script thus:

run script file appPath
run script file appPath2

Actually, no. launch loads an application into memory as a process, but doesn’t run it. run loads an application into memory and runs it. activate loads an application into memory, brings it to the front, and runs it. If the application’s already loaded, already running, or already frontmost, the relevant commands have no effect.

tell application "TextEdit" to launch
--> TextEdit launches (if not already launched) and does nothing.

tell application "TextEdit" to run
--> TextEdit launches (if not already launched) and runs through its startup
--> routine (if not already running), including opening a default window.

tell application "TextEdit" to activate
--> Ditto, but with TextEdit as the frontmost app.

Hi Nigel,

the above code works like a charm.
Thanx for the in dept explanation to the topic! Really appreciate it. :slight_smile:

The reason why i used 2 apps is that the 1st one is a common app that is used to parse information out. But for this particular case, i wanted to do more, parse and insert into iCal.