|
Applescript Patch: A BeginningAppleScript in Quartz Composer would be useful for one particular advantage over Javascript: It has its same dictionaries, etc, wherever it is implemented. That means calls to Address Book, Safari, and System Events. I want AppleScript right now so I can bring another application's window to the front, but I know of plenty of other uses. This is only a decent start, as I can't figure out how to pass a variable number of arguments to the applescript the way I'm doing things AppleScript Patch Goals
Implementation: In Leopard's Official API, create a plugin with an interface. In your header file, specify two inputs. one a boolean, shouldRun, which will tell our patch when to run, and the other an Index (integer), numArgs, that tells us how many variable inputs we need. These are 'real' inputs, as in a patch that completes my goals, we'd have argument support. Create one non-input Objective-C 2.0 properties, a NSString called script. Plunk a text box down in Interface Builder, and bind it to PlugIn.script. This is where the user enters his/her applescript. Scripts are entered into the text box, with arguments passed to any value called %@ or %d or whatever, in order. Here's most of the code for your main block: if (self.shouldRun) { //for errors, we have this! NSDictionary *errorContainer = [[NSDictionary alloc] init]; //Creates our final script by taking user entry and substituting %@ or %d for our real argument. NSString *finalScript = [NSString stringWithFormat: self.script, arg1, arg2]; //note that as I have no idea what I'm doing, we're not gonna have these args. thats for YOU to figure out how to do NSAppleScript *appleScript = [[NSAppleScript alloc] initWithSource:finalScript]; if(![appleScript executeAndReturnError:& errorContainer]) NSLog([errorContainer description]); }; So, who can solve the dynamically creating argument inputs problem?
|
use shellscript patch with "osascript -e 'your applescript goes here'" for one-liners.
perhaps look at the source of the shellscript patch as well to get a model for such things.
i'm in the middle of something fiddly myself, so can't get stuck into this right now.