Point and Click with Keyboard Maestro
Mac Tip #449, 11 August 2010
Keyboard Maestro lets you set up sequences of actions, called macros, and then does them for you. For example, I can set it up to start an application, enter defined text in the right place, click and carry out some menu actions. And so can you. Here are some guidelines and tips.
Please read Turn 100 steps into 1 with Keyboard Maestro for a refresher on the basics of Keyboard Maestro.
Use the coupon
MacTips for a 20% discount on Keyboard Maestro. [Updated] This offer expires at the end of October 2010. It’s free to test the software.
An example sequence
In this Tip I’ll use Keyboard Maestro to open a web browser and go to an URL, then to copy the URL from the browser, open Network Utility and run a Traceroute — all with one click.
My purpose is to show how to use Keyboard Maestro to open a program, click in specified places, insert text in a field, and get information from one program into another.
The all-important Pause
As human beings, when we work through a sequence of actions, such as opening a web browser and typing in an URL, we know when and how long to wait before we take the next step. A web browser may open instantly, or there may be some delay — perhaps if our computer is busy on some other task.
One common reason for macros to fail is because everything happened too quickly. We need to build in delays at certain points, to make sure the previous step has been completed before trying to do the next step.
When you add Actions to a macro, insert a
Pause action from time to time, and set it to maybe 5 seconds or longer. Then in testing see if you can reduce it to a shorter pause.
Macros can include other macros
I have a handy macro that moves and resizes a web browser window. I just like my windows tidy. But moving a window is also a handy trick when you need to click in a specific place.
By moving a window to a defined location, you know that clicking at certain co-ordinates will always hit the target. If you don’t move it first, then the window may not be where you think it is — perhaps you moved it some other time by accident — and your click may miss.
Open Firefox and go to an URL
I set up this sequence of actions to cause Firefox to open my MacTips website:
- Activate Firefox
- This either opens Firefox if it’s not already open (which may take a few moments), or brings it to the front.
- Pause for 3 seconds
- If Firefox isn’t already open it may take a few seconds to start up. On my machine 3 seconds seems to be long enough. On your machine it may open more quickly or more slowly.
- Execute a macro
- This is my macro that moves the window to the top left of my screen: the co-ordinates for the top left corner of the window are 1 pixel across and 22 pixels down. The menu bar takes up 22 pixels. I like that 1 pixel of space on the left too. This macro also sets the size of the window to the dimensions I prefer: 1155 pixels wide and 800 tall.
- Type the
Command (⌘) Tkeystroke.
- This makes a new Tab, so it doesn’t disturb any web page I might already have open.
- Type the
Command (⌘) Lkeystroke.
- This puts the cursor in the Location Bar, ready for the address. Making a new Tab should have put the cursor in the right place. This is just in case it didn’t.
- Insert Text by Pasting
- This enters the URL I specify in the Action, in this case:
- Type the Return keystroke.
- This causes Firefox to attempt to go to the URL specified above.
With any luck, the web page will soon be displayed in the Firefox tab.
Test the macro
Now use the trigger you’ve set for the macro and see if it works. Remember: the macro relies on putting the cursor in the Location Bar in Firefox so don’t click elsewhere while the macro’s running. Just wait.
If the macro doesn’t work, look to see where it failed. You may need to add more or longer pauses. For example, if it started Firefox but didn’t even put the URL in the Location Bar, maybe Firefox wasn’t ready in time. Add a longer pause before trying to paste in the URL.
Run a Traceroute
Sometimes if you can’t reach a website you might use Network Utility to run a Traceroute — it helps identify where the problem is. This next macro:
- copies an URL from the browser
- opens Network Utility
- calls up the Traceroute tab
- pastes in the URL
- edits the domain slightly
- sets the Trace running.
Caveat: I assume the URL is in this form:
http://mactips.info/. If it’s more like this:
http://mactips.info/2010/08/turn-100-steps-into-1-with-keyboard-maestro then my editing won’t be sufficient.
- Get the URL
- Activate the browser, type the
Command (⌘) Lkeystroke to put the cursor in the Location Bar, and then type the
Command (⌘) Ckeystroke to copy the URL. Note: The
CopyAction is a quick way to get the
Command (⌘) Ckeystroke .
- Activate Network Utility and place window
- Activate Network Utility and pause to give it time to start, then move the window so its top left corner is placed at 6 pixels across by 22 down, so we can place subsequent clicks exactly, and pause again to give the window time to move.
- Click on the Traceroute tab
- Click at the correct co-ordinates (on my screen, and after the move in the previous step, that’s 366 pixels across and 48 down). This activates the
Traceroutetab. I couldn’t find any keystroke or menu item to call it up, so clicking was the only way.
- Paste and edit the URL
- The URL I copied from the browser was:
http://mactips.info/, but Traceroute doesn’t like that. After pasting in the copied URL I need to delete the trailing slash by pressing
Delete. Then pressing
Option (⌥) ← (left arrow)puts the cursor after the
Delete7 more times to remove it. Note: The
PasteAction is a quick way to get the
Command (⌘) Vkeystroke .
- Press the
- Finally Keyboard Maestro can press the
Tracebutton to initiate the trace.
How to prevent frustration and annoyance
It takes a lot of writing to describe anything step by step. It may seem like a lot of hard work to set up a macro, and it can take a while. You have to think through the steps. Luckily Keyboard Maestro can help by recording a macro for you, but more on that later.
If you spend 10 minutes setting up a macro that will save you 1 minute per day all year (6 hours over the year!), then you’re winning after the first few days.
And for me it’s not always about time savings either. It’s more the sheer annoyance of having to click a dozen times to do something that’s quite mindless really. One of my macros saves me 5 tedious clicks on a single web page I visit every day. I love it!
Use the coupon
MacTips for a 20% discount on Keyboard Maestro. [Updated] This offer expires at the end of October 2010.
Have you used Keyboard Maestro yet? Tell us about your experiences in the Comments. Have you found any great Tips? Share them with us.