9 Replies Latest reply: May 25, 2012 8:24 AM by Matt-Boy
osmanberg Level 1 Level 1 (0 points)

  Hi All,

    Good day. I am a newbie to AppleScript and writing down this seeking your kind help here.

 

Making my question detail here,

 

Applcation 1 :  Consider this to be some thing kind of server stuff which is running.

Application 2:  Consider this to be an application like Automator or any other automation tool for example Sikuli or Squish

 

My actual scenario is that, When Application 1- is still running and upon its completion I want to instruct to another application to start.

 

Suppose consider that Application 1 is running and when it is finished I want to invoke another application via apple script.

 

So here, I want both the scripts from you people that can do this.

 

> Script for -

 

1. Invoke Application 1 (via Applescript itself) let it run for few minutes(as it is server kind of stuff, i want it to run) when this is complete then I want to invoke the application 2

 

2.  I am manually invoking the application 1 and I am going away,  as it will run for few minutes then on Application completes its job I want Application 2 to be Invoked.

 

 

 

I believe, I am pretty explanatory here, so please help with these

 

Regars,

OsmanBerg

  • 1. Re: How to invoke an application when another applications is started
    Kappy Level 10 Level 10 (226,765 points)

    You can run multiple applications concurrently which means you can start more than one application at the same time or at least sequentially. Is this what you are asking?

  • 2. Re: How to invoke an application when another applications is started
    osmanberg Level 1 Level 1 (0 points)

    Hello Kappy,

    No that's not my point.

     

    My question is, I want invoke and start an application 2 when application 1 finishes its jobs.

     

    scripts for these two

     

     

    1. Invoke Application 1 (via Applescript itself) let it run for few minutes(as it is server kind of stuff, i want it to run) when this is complete then I want to invoke the application 2

     

    2.  I am manually invoking the application 1 and I am going away,  as it will run for few minutes then on Application completes its job I want Application 2 to be Invoked.

  • 3. Re: How to invoke an application when another applications is started
    Keith Barkley Level 5 Level 5 (5,260 points)

    Why not just write a bash script that runs both apps sequentially?

  • 4. Re: How to invoke an application when another applications is started
    osmanberg Level 1 Level 1 (0 points)

    Keith, its requirement that I should use only AppleScript.

     

    So please help me with the AppleScript.

     

    If you dont mind sharing the bash script also no problem, you can share here, it will be useful.

     

    Thanks

  • 5. Re: How to invoke an application when another applications is started
    Camelot Level 8 Level 8 (45,790 points)

    Does Appliction 1 quit by itself when it's done? If so a simple loop should do the trick - periodically check to see if the app is still running:

     

    -- start App1

    tell application "App1" to activate

     

    -- we know it's running

     

    set isRunning to true

     

    tell application "System Events"

      -- do this until the app is no longer running

              repeat until isRunning is false

      -- has the app quit?

                        if (exists application process "App1") = false then

      -- if so, set our flag accordingly

                                  set isRunning to false

                        end if

      delay 2 -- wait 2 seconds before checking again

              end repeat

    end tell

     

    -- if we get here we know the first app has quit, so:

    tell application "App2" to activate

  • 6. Re: How to invoke an application when another applications is started
    osmanberg Level 1 Level 1 (0 points)

    Camelot,

    Good see some scripts for my question

     

    I am not sure on Application 1 will quit itself or not. So what if that it doesnt quit itself and we manually got to do it ?

     

    Please let me know if we have to modify anything on this script to make it run ?

     

    I can understnad the code here, as the the advantage of using AppleScript is that it follows the Natural scripting language. Idea of periodically checking is nice

  • 7. Re: How to invoke an application when another applications is started
    Camelot Level 8 Level 8 (45,790 points)

    I am not sure on Application 1 will quit itself or not. So what if that it doesnt quit itself and we manually got to do it ?

     

    Follow the code - you'll see that the script periodically asks System Events if App1 is running or not. There's no clue (or interest) as to whether it quit itself, or if the user quit it, or if it crashed, or anything else... it's just a simple check - is App1 running or not?

  • 8. Re: How to invoke an application when another applications is started
    osmanberg Level 1 Level 1 (0 points)

    Thank you camelot. I will try this and get back to the same forum.

     

    Will award you with 15 points

  • 9. Re: How to invoke an application when another applications is started
    Matt-Boy Level 1 Level 1 (35 points)

    Do you have control over what is in these scripts? Or are you working with something that you are not allowed to modify?

     

    Based on your answer to the above, the below approaches may or may not help:

     

    1) Put everything in one script. That way, everything that was in script 1 will run and then flow right into the code that was in script 2.

     

    2) Modify script one so that the last step (after it completes everything that needs to be completed) is to launch script 2. That way it will only launch and run when script 1 is complete.

     

    3) Create a 3rd script that launched script 1 and then launches script 2. This is the script that you will run to kick off the process.