Hope someone can help with this, I have bodged together a script that will check if an application is unresponsive and if so it will kill it and reopen. The script is running on OS X 10.4.
It works for every application I’ve tested it on, except for the actual application I need it to run with (QuickMail Server), then it just keeps killing the application even though it’s running perfectly well.
Is there another way to check if an application has crashed?
Thanks
repeat
set shortTimeout to 1
tell application "System Events"
set hungAppProcesses to {}
repeat with oneProcess in (get application processes whose background only is false)
try
with timeout of shortTimeout seconds
get title of oneProcess
end timeout
on error number n
if n is -1712 then set end of hungAppProcesses to unix id of oneProcess
end try
end repeat
hungAppProcesses
end tell
repeat with i in hungAppProcesses
do shell script "/bin/kill -9 " & (i as Unicode text)
end repeat
delay 5
tell application "System Events"
if ((get name of the processes) does not contain "QuickMail Server") then
tell application "QuickMail Server"
activate
end tell
end if
end tell
delay 5
end repeat
I’ve been tweaking and this will now kill and reopen any unresponsive application, just still can’t figure out why QuickMail Server is being killed when it’s running nicely.
repeat
set shortTimeout to 1
tell application "System Events"
set hungAppProcesses to {}
repeat with oneProcess in (get application processes whose background only is false)
try
with timeout of shortTimeout seconds
get title of oneProcess
end timeout
on error number n
if n is -1712 then set end of hungAppProcesses to unix id of oneProcess
if n is -1712 then set hungApp to name of oneProcess
end try
end repeat
hungAppProcesses
end tell
repeat with i in hungAppProcesses
do shell script "/bin/kill -9 " & (i as Unicode text)
delay 5
tell application hungApp
activate
end tell
end repeat
delay 5
end repeat
I don’t have a solution, but was wondering if you have a method of crashing some app on purpose. Also, I don’t think it’s a good idea to crash an app in the first place.
What do you mean by unresponsive and crashed? Do you mean that it is not doing what it is supposed to be doing?
I have created two AppleScript apps. I can’t get both apps to quit with AppleScript, but will try to ‘kill’ them. One is still doing its job and the other is not.
Not sure, but I think you’re testing the app the wrong way with the error -1712. Hope you find your answer and will be thinking of other options.