Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a Java applet that I need to paste lots of text into. However, the paste options doesn't work (neither keyboard shortcut, nor right-button menu).

I'm looking for a way to emulate a keyboard and write automatically all the text I'd like to paste into the textbox in the applet.

share|improve this question
up vote 1 down vote accepted

It's a bit hacky, but you can do this with an AppleScript. Open up AppleScript Editor (in Applications/Utilities) and paste in the following script.

set myString to the clipboard

-- Switch to last application
tell application "System Events"
    keystroke tab using (command down)
end tell
delay 0.5

-- Enter the clipboard text
repeat with i from 1 to length of myString
    set theKey to character i of myString

    tell application "System Events"
        keystroke theKey
    end tell

end repeat

Make sure your applet is the previously used application, and the text you want entered is copied to the clipboard, then hit Run.

The script switches to the last application by emulating commandtab (so be sure your applet is the previous application), waits half a second (this avoids entering text before the app switches), then emulates a key press for all the text in the clipboard.

If you want to make it more reliable (if the app switcher doesn't fire properly), you can try replacing the lines from tell application[…] to delay 0.5 with tell application "YourApp" to activate. Replace YourApp with the name of whatever runs your applet (it may be the applet name, or the runtime environment — whatever's in bold text next to the Apple menu).

Let me know if you have any questions or problems.

share|improve this answer
It worked great, thanks! – ΔλЛ Oct 27 '12 at 21:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.