I want to automate a long sequence of keystrokes that I have to type every time I use a specific web site. How can I do it in Mac OS X. I've tried the Automator. I record the sequence, but when I run it I got this error:

The action “Watch Me Do” encountered an error.

Check the actionʼs properties and try running the workflow again.

link|improve this question

64% accept rate
feedback

4 Answers

up vote 2 down vote accepted

To do this, I created a automator workflow with a Run AppleScript object with this content:

on run {input, parameters}

tell application "Google Chrome" to activate

tell application "System Events"
    keystroke "A"
    keystroke "B"
    keystroke "C"
end tell

return input
 end run

This worked fine for me

link|improve this answer
feedback

In addition to writing your own script, Keyboard Maestro can be used to compose key sequences like this.

link|improve this answer
feedback

You might also want to look at iKey and QuicKeys. I don't think either one will do more than Automator/AppleScript will in this case, but they might be handy otherwise.

link|improve this answer
feedback

You could create a macro with an application like Keyboard Maestro, iKey or QuicKeys.

Many of them also supports something like quick macros. In KBM you can press ⌃F1 to start or stop recording a macro, and then play it back with ⌥F1:

enter image description here


Keypresses can also be emulated with AppleScript:

activate app "TextEdit"
delay 0.5 -- if the script is run with a shortcut that has modifier keys
tell app "System Events"
    keystroke "aaa"
    key code 123 using {shift down, command down} -- ⇧⌘←
end tell

You can run and save scripts with AppleScript Editor and assign shortcuts to them with a utility like FastScripts or by saving them as a services with Automator or ThisService.


The AS keystroke command can only be used to output characters that are found on the current keyboard layout though. It substitutes other characters with some related character or key code 0 (a on QWERTY). Like tell app "System Events" to keystroke "†‡▲ö" outputs ‡‡aa on a U.S. layout.

Inserting longer strings of text with keystroke also takes a visible amount of time. (Like a few seconds for 1000 characters on my Air.)

Another way to insert text is to use the clipboard:

try
    try -- the clipboard can be empty
        set old to the clipboard
    end try
    set the clipboard to "†‡▲ö"
    delay 0.3 -- time to release modifier keys
    tell application "System Events" to keystroke "v" using command down
    delay 0.03 -- often needed after keystroke and key code commands
    set the clipboard to old
    -- the script is wrapped in a try block,
    -- so if `old` is unassigned, it will stop and not display an error message
end try
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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