Torbilicious Torbilicious - 2 months ago 9x
AppleScript Question

Wait for background process

I am creating an applescript that should wait for two processes to finish and then execute some logic. The first is an Application, which is easy to wait for.

set program to "Applications/"

repeat until (application program is not running)
delay 1
end repeat

Now for my background task that doesn't work since it is a directly called executable not an Application. If it helps the process is aria2. Could anyone tell me how this works, or point me in the right direction to find an answer?


Try using pgrep to look for the process id of a process called aria2 like this:

do shell script "/usr/bin/pgrep aria2"

I don't have aria2 so I am only guessing its process name - try it in the Terminal first to see if it works:

pgrep aria2

There will be no output if it is not running.

To see fuller output, run:

ps -aef | grep -i aria

If you want to check it in a loop, you could do this sort of thing:

set ariarunning to 0
repeat until ariarunning > 0
      set ariarunning to do shell script "/usr/bin/pgrep aria"
   end try
end repeat