0

I am searching for an AppleScript command which is similar to Visual Basic Script Sendkeys command. I want to let a programm type something at itself.

0

1 Answer 1

2

From the AppleScript System Events dictionary:

key code integer or list of integer : The key code(s) to be sent. May be a list.

    [using command down/‌control down/‌option down/‌shift down or list of command down/‌control down/‌option down/‌shift down] : modifiers with which the key codes are to be entered

keystroke text : The keystrokes to be sent.

    [using as above]

Some examples illustrating their use:

tell application "System Events"       
    key code 124 using {shift down, command down} --> Right arrow
    key code 8 using command down --> ⌘-C
    key code {4, 14, 37, 37, 31, 47} --> H, e, l, l, o, .

    keystroke "v" using command down --> ⌘-V
    keystroke "Hello." --> H, e, l, l, o, .
end tell

(Note: I stylised ⌘-C and ⌘-V with their uppercase representations, but these indicate Cmd+C or V, respectively, without use of the Shift key.)

keystroke can also accept the AppleScript constants tab, space return, and quote.

The target is always the application window that has focus, so it’s important to set the focus to the desired application before issuing these commands (e.g. tell application "Finder" to activate).

Here’s a great reference for the keycodes as well as a detailed overview of these commands including more examples.

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