Good morning everybody and thanks for chipping in, I was away and it surely has been busy.
I like to test this script (not that I do not believe any of you ☺ ) so how do I let a applications ˜hang’?
I made a script that can not be executed but that does not seem to do the trick as it does not really make it hang. So how to flip-out a programme so I can test the script? Any ideas?
yes a good solution. any document open will however not be saved. however you are now exposing your admin password too anybody that can read the script, so will need to be saved as a run only script for a bit of security.
In a Terminal window try kill -STOP PID to “hang” a process. Use kill -CONT PID to unhang it. Respectively, these send the SIGSTOP and SIGCONT signals to the process which cause the kernel to stop and to resume scheduling it. Only processes that are scheduled are ever allowed to execute. This should effectively make the process appear hung. Get the PID with either the ps command or by scripting System Events: tell application “System Events” to get unix id of application process “Preview”.
If you stop the enough things (Dock, Terminal, Finder, SystemUIServer (Spotlight), and Script Editor, all other launcher applications, etc.) it may be difficult to resume anything without doing so via a remote login (the only other alternative being a forced restart). I suggest limiting your testing to suspending and resuming some app where the effects will be innocuous, perhaps Preview, or a browser that you do not regularly use.
If you cannot use Terminal, I think Bokeh has the same ability to send SIGSTOP and SIGCONT to application processes (probably with a bit of eye candy, too). I have never even downloaded it though, so I am just guessing. It says it requires 10.5, so that may not work for the original poster.
Sorry, I was mistaken.
Hanging apps is not the same as processes with state Z(ombie) in ps
You could check all apps by sending an Apple Event and wait for a controlled timeout error
property shortTimeout : 5
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 comtents of oneProcess
end try
end repeat
hungAppProcesses
end tell
property shortTimeout : 5
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 contents of oneProcess
end try
end repeat
hungAppProcesses
end tell
repeat with i in hungAppProcesses
quit application i
end repeat
the scriopt now hangs on:
quit application i
I get the message:
Can’t get application (application process “Preview”) of «script».
Next try, the apps have to be killed in the terminal, because a hanging app doesn’t respond to the quit event
property shortTimeout : 5
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 " & (i as Unicode text)
end repeat
tell application "System Events" to set pid to the unix id of process "Preview" as Unicode text
do shell script "/bin/kill -STOP " & pid
to force the process to hang and then I run the script.
It waited the 5 seconds and killed the app. The list hungAppProcesses contained the pid of Preview.app
After the second run of the script the list hungAppProcesses was empty