py-appscript

8. Examples

Identifying Applications

# application "Macintosh HD:Applications:TextEdit.app"
textedit = aem.Application('/Applications/TextEdit.app')

# application "TextEdit"
textedit = aem.Application(aem.findapp.byname('TextEdit'))

# application "TextEdit" of machine "eppc://my-mac.local"
textedit = aem.Application('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').byindex(1).property('ctxt').elements('cpar').end

# paragraphs 2 thru last of first document
aem.app.elements('docu').first.elements('cpar').byrange(
        aem.con.elements('cpar').byindex(2), 
        aem.con.elements('cpar').last)

# paragraphs of document 1 where it != "\n"
aem.app.elements('docu').byindex(1).elements('cpar').byfilter(aem.its.ne('\n'))

Sending Events

# quit TextEdit
textedit.event('corequit').send()

# name of TextEdit
print textedit.event('coregetd', {'----': aem.app.property('pnam')}).send()

# count documents of TextEdit
print textedit.event('corecnte', {'----': aem.app.elements('docu')}).send()

# make new document at end of documents of TextEdit
textedit.event('corecrel', {
        'kocl': aem.AEType('docu'), 
        'insh': aem.app.elements('docu').end
        }).send()