iTunes, NSAppleScript, and timeout
iTunes, NSAppleScript, and timeout
- Subject: iTunes, NSAppleScript, and timeout
- From: patrick machielse <email@hidden>
- Date: Thu, 22 Mar 2007 12:57:53 +0100
I'm creating a program that will talk to iTunes using AppleScript for
a longer time. The user may be working with iTunes while my program
is going about its business, so I want to handle the situations when
iTunes may not respond to Apple Events. It seems that I can use the
AppleScript 'clause' (is that the right term?) 'with timeout of ...
seconds' to make this happen.
To test this I created a small application that executes the
following script:
get.applescript
===============
tell application "iTunes"
with timeout of 5 seconds
get version
end timeout
end tell
From my Cocoa application I execute this script in the following
manner:
MainController.m
================
- (IBAction)doScript:(id)sender
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"get"
ofType:@"applescript"];
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:
[NSString stringWithContentsOfFile:path]];
NSDictionary *error = nil;
NSAppleEventDescriptor *descriptor = [script
executeAndReturnError:&error];
if ( error ) {
NSLog(@"error: %@", error);
}
NSLog(@"result: %@", descriptor);
[script release];
}
To trigger the timeout behavior I choose 'Open...' in iTunes to show
the modal open panel.
Timing out seems to work fine most of the time _except_ when iTunes'
open panel is up the first time doScript: is executed. In that case I
have to sit through the entire default timeout period (2 minutes).
Not until the open panel is closed and the script executes once
without timeout does the desired 5 second timeout take effect.
Is this a bug (looks like it), and what is the general approach to
handling 'unresponsive' applications?
thanks,
patrick
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden