How to use Applescript to type in a application? I'm trying to type in another application using Applescript, and it keeps giving me this error: Can't get keystroke of &quot;string&quot;.
This is my code.
on run {}
    tell application &quot;My Application&quot;
        set str to &quot;string&quot;
        repeat
            keystroke str
            keystroke return
            delay (random number from 5.0 to 10.0)
        end repeat
    end tell
end run

Also, when I replace application with process, it types into the Script Editor instead of the desired application. It would be preferred if I use the application name instead of it's process ID, otherwise I'd have to change the Process ID variable every time.
You need to use System Events to send the keystrokes not the app, try something like this:
on run {}
    tell application &quot;My Application&quot; to activate
    set str to &quot;string&quot;
    repeat
        tell application &quot;System Events&quot; to keystroke str
        tell application &quot;System Events&quot; to keystroke return
        delay (random number from 5.0 to 10.0)
    end repeat
end run