"Pasting" text to Java applet through keyboard emulation 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.
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.