Mac OSX Apple Script, How do I make Apple Script push keys on an application
You might also add a delay somewhere in the loop to make it easier to stop the script:

activate application "TextEdit"
delay 0.5 -- time to release modifier keys if the script is run with a keyboard shortcut
tell application "System Events"
    repeat while name of (process 1 where frontmost is true) is "TextEdit"
        repeat 50 times
            key code 126 -- up
            delay 0.1
        end repeat
        repeat 50 times
            key code 125 -- down
            delay 0.1
        end repeat
        delay 0.5
    end repeat
end tell


See Events.h or my website for the key codes.