10

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.

14

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

| improve this answer | |
  • 2
    On OS X El Capitan I got an error when including the first and last two lines. Removing them made the script work fine. – Eneko Alonso Aug 3 '16 at 16:59
3

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

| improve this answer | |
  • 1
    I've used Keyboard Maestro -- excellent product and great support! – JESii Oct 20 '16 at 13:48
2

You could create a macro with an application like Keyboard Maestro, iKey or QuicKeys. Many of them also support something like the quick macros in Keyboard Maestro. You can press ⌃F1 to start or stop recording a macro, and then play it back with ⌥F1.

You can also emulate keypresses with AppleScript. The delay at the start is not needed if the script is run with FastScripts.

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

The keystroke command can only be used to insert characters that are included in the current keyboard layout. If the text is long enough, there's also a visible delay when it's inserted.

Another way to insert text is to use the clipboard:

set the clipboard to "aa"
delay 0.05
tell application "System Events" to keystroke "v" using command down
| improve this answer | |
0

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.

| improve this answer | |
0

Unfortunately, you cannot add a mouseclick function in any of these or workflow. Even applescript has a difficult time implementing a mouse click in an app.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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