macosapplescript

Typing with Applescript


Is it possible to have my mac type for you with applescript? What I want is this: when compiled, this applescript will type a phrase, then press enter. Is there any code simulating the pressing of keys?


Solution

  • The keystroke command will work for you.

    tell application "System Events" to keystroke "A phrase" & return & "Another phrase"
    

    If you want a specific application to do the typing, just do something along these lines:

    tell application "System Events" to tell process "TextEdit" to keystroke "A phrase" & return & "Another phrase"