Dock monitoring

I’m trying to find out if there’s any way to check on the status of an item in the Dock via Applescript, either through apple events or GUI scripting. I know the Dock itself isn’t scriptable. What I’m ultimately trying to do is write a script which opens suspect QT files and then determines whether QuickTime Player has stopped responding. I’ve tried using a ps shell script but according to ps, even when QT has hung while chewing on a corrupted stream, it thinks the app is happily doing what it’s supposed to. I know there’s an apple event which tells the Dock that an app hasn’t managed to open a window when a file is opened and that’s what causes the app’s Dock menu to show the “Application not Responding” item. Any way to intercept this via AppleScript?

Any help would most sincerely and humbly appreciated.

Did you set a timeout on the document open event? If you get a filehandle response back from an app, it probably opened the doc fine.

To check for hung/crashed apps, I usually just send it a simple event like asking for its version number with a short timeout. No reponse == problem. Then kill the app, restart and move on to the next document. Works great.

Thanks for the response - that’s a great idea, I’ll have to play with that. Last night though I stumbled upon the Dock UI solution and it appears to work fine. Got clued in when I downloaded PreFabUIBrowser - the app itself turned out to not be able to do what I wanted but after I gave up on that I looked at the example scripts and one had exactly what I needed - turns out this ability is new with Tiger. Here’s what came of it:

set theFolder to choose folder

tell application "System Events"
	set theFiles to every file of theFolder
end tell

repeat with i from 1 to the count of theFiles
	set theItem to item i of theFiles
	set itemName to the name of theItem
	ignoring application responses
		tell application "QuickTime Player"
			open theItem
		end tell
	end ignoring
	delay 5 -- So System Events doesn't get ahead of the actual window creation for the movie and so the status of the Dock menu can settle down
	tell application "System Events"
		tell process "Dock"
			tell list 1
				set QTPlayer to UI element "QuickTime Player"
				tell QTPlayer
					perform action "AXShowMenu"
					if menu item "Quit" of menu 1 exists then -- QTPlayer is relatively happy with the file that's been opened
						tell application "System Events"
							do shell script "killall QuickTime\ Player" -- Since QT is polite enough to report that it can't deal with some files, it leaves up a dialog box so instead of writing a routine for dealing with that I just opted to have the app killed; I'm only concerned with files that cause a crash or hang
						end tell
					else
						if menu item "Force Quit" of menu 1 exists then -- The app has "hung" while dealing with a funky stream
							click menu item "Force Quit" of menu 1
							tell application "Finder"
								set the name of theItem to " " & itemName
							end tell
						else -- If neither "Quit" or "Force Quit" are available then that means QTPlayer isn't currently running which means the last opened file has crashed it
							tell application "Finder"
								set the name of theItem to " " & itemName
							end tell
						end if
					end if
				end tell
			end tell
		end tell
	end tell
end repeat
say "Done chewing on those files boss."
display dialog "Done chewing on those files, boss."