Re: test if another app has hung
Re: test if another app has hung
- Subject: Re: test if another app has hung
- From: has <email@hidden>
- Date: Wed, 2 Apr 2008 01:46:50 +0100
Martin Redington wrote:
There were some AppleScript based approaches, but they all seemed to
involve activating the app ...
Shouldn't do, as long as you check to see if the application is
running first. That said, you may not want to use AppleScript itself
as it has issues running in background threads and running it on the
main thread will block your own app's main event loop. You could knock
up your own code using AEBuildAppleEvent and AESendMessage, or here's
one I did earlier with objc-appscript (NSThread stuff not included):
// To generate default glue: osaglue -o DefaultGlue
#import "DefaultGlue/ASDefaultGlue.h"
#define TARGET_APP_ID @"com.apple.finder"
#define TIMEOUT_IN_SECONDS 120
// Target the application
ASDefaultApplication *app = [[ASDefaultApplication alloc]
initWithBundleID: TARGET_APP_ID];
// Check if it's running
if ([app isRunning]) {
// Send no-op event
NSError *error;
[[[app launch] timeout: TIMEOUT_IN_SECONDS] sendWithError: &error];
OSStatus err = [error code];
/*
* Check for unexpected termination or timeout error
* (Note: event timeout should give error -1712 (errAETimeout),
* but AESendMessage may return error -609 (connectionInvalid)
* instead - another reason to check for both codes.
*/
if (err == connectionInvalid || err == errAETimeout)
NSLog(@"Unresponsive.");
else
NSLog(@"OK");
} else
NSLog(@"Not running.");
[app release];
HTH
has
--
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden