• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: test if another app has hung
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: Is there a Source List control in Cocoa
  • Next by Date: Re: Finding out about new windows.
  • Previous by thread: Re: test if another app has hung
  • Next by thread: Re: Saving NSManagedObject in Core-Data
  • Index(es):
    • Date
    • Thread