I'm using a command-line app in an AppleScript, and I need the script to wait for the process to finish running before continuing. (And yes, I want the terminal to open and to see the app run.)
I wrote this code, based on an existing question:
activate application "Terminal"
tell application "System Events"
repeat until visible of process "Terminal" is true
end repeat
end tell
tell application "System Events" to keystroke "app_name option"
tell application "System Events" to keystroke return
delay 2
set thePID to do shell script "app_name option > /dev/null 2>&1 & echo $!"
repeat
do shell script "ps ax | grep " & thePID & " | grep -v grep | awk '{ print $1 }'"
if result is "" then exit repeat
delay 2
end repeat
-- more code...
Everything is working in my script, except for the part where I need it to wait for the command-line app to complete.
How can I make this work? What exactly does the part starting with set thePID do?