AppleScript is a scripting language created by Apple to easily control OSX applications. It is really simple to understand but sometimes is hard to find how to do something.

If you need to execute some keyboard commands from your script you have to “tell” System Events what keystroke simulate:

tell application "System Events"
    -- add the keystroke you need here
    -- ...
    delay 0.2
end tell

Here are some useful keystrokes:

Copy:
keystroke "c" using {command down}
Paste:
keystroke "v" using {command down}
Return:
keystroke return
Arrow keys
key code 123 -- left arrow Key
key code 124 -- right arrow Key
key code 126 -- up arrow Key
key code 125 -- down arrow Key