NSAppleScript question
NSAppleScript question
- Subject: NSAppleScript question
- From: Matthew Delves <email@hidden>
- Date: Sat, 2 Feb 2008 18:12:43 +1100
Greetings,
I'm currently bashing my head against the wall (rather painfully)
trying to get NSAppleScript functioning the way I want.
How I currently have this setup is there are several applescript
scripts that are located in the resources section of the main bundle
and I am trying to load them with the following code.
NSDictionary *loadError = [[NSDictionary alloc] init];
NSDictionary *error = [[NSDictionary alloc] init];
NSAppleEventDescriptor *returnDescriptor = nil;
NSString *scriptLocation = [[NSString alloc] initWithFormat:@"%@/%@",
[[NSBundle mainBundle] resourcePath],
@"RSITunesLaunchApplescript.scpt"];
NSURL *fileURL = [[NSURL alloc] initWithString:scriptLocation];
NSFileManager *manager = [NSFileManager defaultManager];
NSAppleScript *scriptObject = nil;
// Create the script here
if([manager fileExistsAtPath:scriptLocation]) {
scriptObject = [[NSAppleScript alloc] initWithContentsOfURL:fileURL
error:&loadError];
// Both scriptObject and loadError are null for some unknown reason
if(scriptObject == nil) {
NSLog(@"The error is: %@", [loadError
valueForKey:NSAppleScriptErrorMessage]);
}
}
NSLog(@"%@", scriptObject);
// Run the script
NSLog(@"executing script");
if(scriptObject != nil)
returnDescriptor = [scriptObject executeAndReturnError: &error];
if ([returnDescriptor descriptorType]) {
NSLog(@"script executed sucessfully.");
} else {
NSLog(@"Script execution has gone a bit pear shaped: %@",
[error objectForKey: @"NSAppleScriptErrorMessage"]);
}
What is happening is that the NSFileManager is correctly showing the
existance of the applescript file though when I use NSAppleScript
initWithContentsOfURL: error: I get both objects becoming nil.
As far as the configuration for the project, I'm using XCode 3,
Leopard and have Garbage Collection turned on.
Any help would be greatly appreciated as my head is rather sore.
Thanks,
Matthew Delves
_______________________________________________
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