views:

43

answers:

1

Hello, I'm making an application, in which I need to run a code that will tell system events to keystroke a certain phrase. Like in an AppleScript, I would do:

Tell Application "System Events" to keystroke "This is a test"

I don't know how to do this from Xcode, and I would really appreciate any help. Thank you!

A: 

You can run an AppleScript from code, e.g., using OSACompileExecute. Also see QA1026.

Alternately, you can post keyboard events using the CGEvent APIs. With recent OSes, you may be able to avoid posting each letter individually using CGEventKeyboardSetUnicodeString.

JWWalker