1

I am launching an a jar application from apple script.

do shell script quoted form of jvmpath & " -jar -XstartOnFirstThread -Dapple.awt.UIElement=true -Dfile.encoding=UTF8 " & quoted form of jarpath & " " & quoted form of parameters

The script keeps running till i quit my jar application.

But i am required to launch another application form shell script.

Since i am doing this in a Cocoa app i want to do this in the background.

Thus, can i launch multiple scripts in multiple instances of terminal (so that they aren't blocking one another).

Note: I tested it by running the command in two different terminal windows, works as expected.

2
  • if you don't want to wait end of 'do sheet script' command, you must redirect its output somewhere else, to a file or nowhere. for instance adding '< /dev/null' (without quotes) at end of you 'do shell' command will redirect output to no-where. then your script will not wait for completion, and it will keep running. Commented Dec 2, 2016 at 6:27
  • @pbell I came across the solution and have it as a backup. But the idea is to start two background processes. Doing so will allow me to get a call back to my cocoa app when the jar is exited. Commented Dec 2, 2016 at 8:14

1 Answer 1

2

See Technical Note TN2065, specifically the answers to the questions "I want to start a background server process; how do I make do shell script not wait until the command completes?" and "I have started a background process; how do I get its process ID so I can control it with other shell commands?".

The AppleScript code to run two commands in the background would look like this:

set pid1 to do shell script command1 & " &> /dev/null & echo $!"
set pid2 to do shell script command2 & " &> /dev/null & echo $!"

The pid1 and pid2 variables will be set to the process ids of the two commands. You can later check whether the commands are still running by calling a function like this one:

on isProcessRunning(pid)
    try
        do shell script "kill -0 " & pid
        set isRunning to true
    on error
        set isRunning to false
    end try
    return isRunning
end isProcessRunning
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.