How can I use AppleScript to type in a specified area on the screen? I've tried the keystroke command, but it doesn't seem to work. Also, how can I use AppleScript to display an image? Here is the code I have so far:

set theText to text returned of (display dialog "Put what you want to autotype here." default answer "" buttons {"OK", "cancel"} default button 1)
display dialog "select where you want me to type " & theText & " Your text will be typed in the area selected. you have 10 seconds to select once you click 'OK'" buttons {"OK"}
delay 10
say "typing"
--command for typing here
  • 3
    i think you need to learn to walk before you can run. Try a beginner's guide - computers.tutsplus.com/tutorials/… or macosxautomation.com/applescript/firsttutorial/index.html would be a fair start. Also, Ask Different is designed for one Question, one Answer. Multiple Questions need to be split. You also need to show what research you have done so far & what specific issue you are facing. Questions that are too broad will just be closed.
    – Tetsujin
    Commented Jul 5, 2015 at 17:36
  • sorry, but that's not helpful a bit. Commented Jul 5, 2015 at 21:19
  • 2
    Which problem are you trying to solve in the end using the script (e.g. what is this "specified area": a window, a dialog box, something else)? Also your script seems to be syntactically incorrect, is it taken out of a bigger script?
    – nohillside
    Commented Jul 6, 2015 at 11:57

2 Answers 2

tell application "System Events"
    set textToType to "text here"
    keystroke textToType
end tell

Replace within the quotes of "text here" to what ever you need.

  • 1
    Actually all the delays are not required. You can just use keystroke "any text" to write text and keystroke return to type the return key. Commented Apr 1, 2020 at 10:31
  • 1
    Put some warning on it it ruined some of my code :D next time I read a code before launching it. Commented Sep 25, 2020 at 12:51
  • Yeah seriously, why an infinite loop? Screwed up loads of code and stuff on my computer.
    – callum
    Commented Mar 31, 2021 at 12:30

You can also use key code to type individual keys or achieve most functions using your keyboard.

key code 8 using {command down, shift down} --> ⌘+shift+C

Here is the full list of key codes: https://eastmanreference.com/complete-list-of-applescript-key-codes

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .