Examples

To run the following examples using the interactive Python interpreter, open a new window in Terminal.app, type python and hit return. Once the interpreter is running, import the appscript module's contents using from appscript import *

Create a new "Hello World!" document in TextEdit:

app('TextEdit').documents.end.make(
    new=k.document,
    with_properties={k.text: 'Hello World!\n'}
    )

Get the names of folders in user's Home folder:

# tell app "Finder" to get name of every folder of home

app('Finder').home.folders.name.get() # Python

Count the words in the front TextEdit document:

# tell app "TextEdit" to count words of document 1

app('TextEdit').documents[1].words.count()

Delete all the empty paragraphs in the front TextEdit document:

#tell app "TextEdit" to delete ¬
#       (every paragraph of document 1 where it = "\n")

app('TextEdit').documents[1].paragraphs[its == '\n'].delete()

Make an empty folder named 'My Folder' in Documents folder:

# tell app "Finder" to make new folder ¬
#       at folder "Documents" of home ¬
#       with properties {name:"My Folder"}

app('Finder').make(new=k.folder,
        at=app.home.folders['Documents'],
        with_properties={k.name: 'My Folder'})

Get the name of everyone in Address Book who has the email address 'foo@bar.com':

# tell application "Address Book" to get name of every person ¬
#       where value of every email contains "foo@bar.com"

app('Address Book').people[
        its.emails.value.contains('foo@bar.com')
        ].name.get()

Additional examples are included in the appscript package.