// // APApplescriptHandler.h // Helper Class to perform simple Applescript Message to an external // Application from within a Cocoa App. // // You are free to examine, use, alter and redistribute this code - // but please drop me a mail in any case - especially if you // changed something for better. // // Usage of class: // APApplescriptHandler * handler = [[APApplescriptHandler alloc] initWithApplicationName:@"iTunes"]; // [handler performMessage:@"playpause"]; // NSString * string = [handler getStringForMessage:@"name of current track"]; // NSArray * array = [handler getArrayOfStringsForMessage:@"name of playlists"]; // // Please excuse any bugs (of course, I do not take any warranties) // and even more my ugly english. // // Created by Stefan Mueller on 06.07.06. // Copyright 2006 Arabian Penguins. All rights reserved. // #import @interface APApplescriptHandler : NSObject { NSString *application; NSDictionary *error; } // Designated Initializer -(id)initWithApplicationName:(NSString *)applicationName; // Accessors -(NSString *)applicationName; -(NSDictionary *)error; /* Convienience Methods They send the Message to the our application, providing a try and tell frame. You usually will use those. If the application did not return what was to be expected, we will return nil; errors will be registered in our error-dictionary. */ -(bool)performMessage:(NSString *)message; -(NSString *)getStringForMessage:(NSString *)message; -(NSArray *)getArrayOfStringsForMessage:(NSString *)message; /* Worker Methods Of course you can evaluate more complex (and complete!) scripts too, but then it is up to you to make sure it really works. These methods will not take care of our application and will just try to evaluate the result of the script. If we can spot an error, we will return nil, please check our error-dictionary what went wrong. But of course, the fault for every error is your script... */ -(bool)performScriptWithSource:(NSString *)sourceCode; -(NSString *)getStringForScriptWithSource:(NSString *)sourceCode; -(NSArray *)getArrayOfStringsForScriptWithSource:(NSString *)sourceCode; // raises a NSException if the Script does not return a list. @end