Can't script keystrokes!

No matter what application I try, I cannot get Applescript automate keystrokes. I have written several of my own scripts as well as copy+pasted many from this BBS, but I keep getting the Execution Error: “SystemEvents got an error: NSCannotCreateScriptCommandError”.

I am mainly trying to learn how to enter text into Terminal.app with something like:

I have done a few variations of the above and all produce the same error.

I have also tried the same script with TextEdit and AppleWorks, and I have tried a few scripts from here with the same apps.

Any insight would be appreciated.

I wasn’t sure about this at first, so I tried both ways… neither one works.

Did you go to the Universal Access pref pane and “Enable access for assistive devices”? It’s required for GUI scripting.

– Rob

I did now, but I’m still getting the same error.

Which version of Mac OS and System Events are you running?

tell application “System Events” to version
display dialog result

– Rob

10 .2.6 and 1.1.2

You need System Events 1.2 for UI scripting in OS X 10.2.x. This was available only as a beta until Panther was released. If it’s available now, I don’t know where Apple has hidden it.

– Rob

One option for keystrokes is Extra Suites, which offers much more than keystrokes.

– Rob

Thanks Rob. Extra Suites works great.

I did a search for System Events 1.2 and found one source for it, but the install package was damaged or something… I could not get it to install.

Did you decompress it with StuffIt Deluxe/Expander 8.0? If so, updating to version 8.0.1 should solve the problem with the package.

– Rob

Rob, the .sit file was fine - I have 8.01. The problem occurs when the Installer app tries opening the .pkg package.

The script is constructed incorrectly. It must address the Terminal process (running application)

tell application “Terminal” to activate
tell application “System Events”
tell process “Terminal”
keystroke “sampletexthere”
end tell
end tell