Thanks to help received to my earlier posts I am now nearly finished my first (and hopefully not last) AppleScript project. However, I have one problem outstanding.
My AppleScript Application is a GUI front end to a command line program which takes 40 minutes to execute. In order not to “freeze” my AppleScript Application I run it as background process. The code to invoke it is:
do shell script myScript >/dev/null 2>&1 & echo $!
set PID to the result
I save the PID so that I can kill the process if the user quits the AppleScript Application. Because myScript creates child processes of its own, I kill using the following:
do shell script "kill -9 -" & PID
The last dash ensures that all the processes in the same group as PID (i.e. all its children) are killed also.
My AppleScript Application actually needs to invoke myScript several times in sequence. Therefore, an ivocation of myScript triggers one of two Apple Events
-
“doneIt” on success.
-
“error” if there is an error.
In order for my AppleScript application to receive the above two events I have two hidden buttons in the main window.
The last thing I need to do is where I am having a problem. I need to send a result back from myScript with each event. I tried to tell the Apple Script application to set some properties but I can’t get this to work.
At the moment myCommand looks like:
[code]#!/bin/sh
function doneIt() {
/usr/bin/osascript <<EOT
tell application “$1”
tell button “done” of window “main” to perform action
end tell
EOT
}
function error() {
/usr/bin/osascript <<EOT
cat <<EOT
tell application “$1”
set errMsg to “$2”
tell button “error” of window “main” to perform action
end tell
EOT
}
theApp=“My AppleScript Application”
command=“$1 $2 $3 $4”
out=$command
if [ $? -eq 0 ]
then
doneIt $theApp
else
error $theApp $out
fi[/code]
What is wrong? How do tell “My AppleScript Application” to set properties from my shell script?