7. Examples
Identifying applications
// application "TextEdit"
textedit = [[AEMApplication alloc] initWithName: @"TextEdit.app"];
// application "Macintosh HD:Applications:TextEdit.app"
fileURL = [NSURL fileURLWithPath: @"/Applications/TextEdit.app"];
textedit = [[AEMApplication alloc] initWithURL: fileURL];
// application "TextEdit" of machine "eppc://my-mac.local"
eppcURL = [NSURL URLWithString: @"eppc://my-mac.local/TextEdit"];
textedit = [[AEMApplication alloc] initWithURL: eppcURL];
Building references
// name [of application]
[AEMApp property: 'pnam'];
// text of every document
[[AEMApp elements: 'docu'] property: 'ctxt'];
// end of every paragraph of text of document 1
[[[[[AEMApp elements: 'docu'] at: 1]
property: 'ctxt']
elements: 'cpar'] end];
// paragraphs 2 thru last of first document
[[[[AEMApp elements: 'docu'] first]
elements: 'cpar'] byRange: [[AEMCon elements: 'cpar'] at: 2]
to: [[AEMCon elements: 'cpar'] last]];
// paragraphs of document 1 where it != "\n"
[[[[AEMApp elements: 'docu'] at: 1]
elements: 'cpar'] byTest: [AEMIts notEquals: @"\n"]];
Sending events
// quit TextEdit
evt = [textedit eventWithEventClass: 'aevt' eventID: 'quit'];
[evt send];
// name of TextEdit
evt = [textedit eventWithEventClass: 'core' eventID: 'getd'];
[evt setParameter: [AEMApp property: 'pnam'] forKeyword: '----'];
[evt send];
// count documents of TextEdit
evt = [textedit eventWithEventClass: 'core' eventID: 'cnte'];
[evt setParameter: [AEMApp elements: 'docu'] forKeyword: '----'];
[evt send];
// make new document at end of documents of TextEdit
evt = [textedit eventWithEventClass: 'core' eventID: 'crel'];
[evt setParameter: [[AEMType typeWithCode: 'docu'] forKeyword: 'kocl'];
[evt setParameter: [[AEMApp elements: 'docu'] end] forKeyword: 'insh'];
[evt send];