One way to create a useful script is to start with an existing script that performs tasks similar to the one you want to automate, and then edit the script.
You can use Script Editor to open scripts that have been saved as applications, compiled scripts, or text files.
A number of example scripts are included with Mac OS X, and more examples are available on the AppleScript website.