FROM : has
DATE : Wed Apr 02 02:46:50 2008
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
DATE : Wed Apr 02 02:46:50 2008
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
| Related mails | Author | Date |
|---|---|---|
| Ben Dougall | Apr 1, 12:28 | |
| Jean-Daniel Dupas | Apr 1, 12:46 | |
| Ron Fleckner | Apr 1, 12:49 | |
| Ben Dougall | Apr 1, 12:55 | |
| Martin Redington | Apr 2, 00:27 | |
| John Stiles | Apr 2, 00:58 | |
| has | Apr 2, 02:46 |






Cocoa mail archive

