objc-appscript

PreviousUpNext appscript / aem

1. What is appscript?

Objc-appscript is a high-level Apple event bridge that allows you to control scriptable Mac OS X applications from Objective-C programs.

For example, to get the value of the first paragraph of the topmost document in TextEdit:

TEApplication *textedit = [[TEApplication alloc]
 initWithName: @"TextEdit.app"];
NSString *result = [[[[[[textedit documents] at: 1] 
 paragraphs] at: 1] get] send];

This is equivalent to the AppleScript statement:

tell application "TextEdit"
 get paragraph 1 of document 1
end tell

Appscript builds upon the Apple Event Manager and Foundation APIs to provide:

  1. a high-level RPC mechanism for sending commands to applications via Apple events
  2. a mechanism for converting data between common Foundation and Apple event types
  3. a simple programmatic query language for identifying one or more objects in an application's object model
  4. a glue code generator for representing these object model "references" in human-readable form based on application-defined terminology
  5. a clean, object oriented-like syntax for ease of use.

Appscript requires Mac OS X 10.3 or later.

"Hello World!"

The following program uses appscript to create a new "Hello World!" document in TextEdit:

#import <Foundation/Foundation.h>
#import "TEGlue.h"
int main(int argc, char *argv[]) {
 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 	
 TEApplication *textedit;
 TEMakeCommand *makeCmd;
 
 textedit = [[TEApplication alloc]
 initWithName: @"TextEdit.app"];
 
 makeCmd = [[[textedit make] new_: [TEConstant document]]
 withProperties: [NSDictionary dictionaryWithObjectsAndKeys:
 @"Hello World!\n", [TEConstant text], nil]];
 [makeCmd send];
 
 [textedit release];
 [pool release];
 return 0;
}
PreviousUpNext

AltStyle によって変換されたページ (->オリジナル) /