8. Examples
Identifying applications
# application "Macintosh HD:Applications:TextEdit.app"
textedit = AEM::Application.by_path('/Applications/TextEdit.app')
# application "TextEdit"
textedit = AEM::Application.by_path(FindApp.by_name('TextEdit'))
# application "TextEdit" of machine "eppc://my-mac.local"
textedit = AEM::Application.by_url('eppc://my-mac.local/TextEdit')
Building references
# name (of application)
AEM.app.property('pnam')
# text of every document
AEM.app.elements('docu').property('ctxt')
# end of every paragraph of text of document 1
AEM.app.elements('docu').by_index(1).property('ctxt').elements('cpar').end
# paragraphs 2 thru last of first document
AEM.app.elements('docu').first.elements('cpar').by_range(
AEM.con.elements('cpar').by_index(2),
AEM.con.elements('cpar').last)
# paragraphs of document 1 where it != "\n"
AEM.app.elements('docu').by_index(1).elements('cpar').by_filter(AEM.its.ne("\n"))
Sending events
# quit TextEdit
textedit.event('aevtquit').send
# name of TextEdit
p textedit.event('coregetd', {'----' => AEM.app.property('pnam')}).send
# count documents of TextEdit
p textedit.event('corecnte', {'----' => AEM.app.elements('docu')}).send
# make new document at end of documents of TextEdit
textedit.event('corecrel', {
'kocl' => AEM::AEType.new('docu'),
'insh' => AEM.app.elements('docu').end
}).send