TextEdit includes AppleScript terms that let you automate tasks using scripts. You can use scripts to add text, copy information, set styles, or export information from a TextEdit document for use by another application.
To see the TextEdit terms and write scripts, you can use AppleScript Editor, included with Mac OS X.
Open AppleScript Editor, in the Utilities folder in the Applications folder.
Choose File > Open Dictionary.
Select TextEdit and click Choose.
To learn more about AppleScript and how to use scripting terms, choose Help > AppleScript Help while you’re working in AppleScript Editor, or visit the AppleScript website.