How to Automate Form Filling with Keyboard Maestro (For Big Sur)

03 Mar 2021 11:12 UTC-08:00

Working to help a friend automate some form entry I went to look back into how I had automated a similar task a few years ago with Keyboard Maestro. I was surprised at how I remembered the steps to input form fields (Big props to the KM team for making it so easy to do.)

But when I went to test adding value to the field, I got nothing. If you're trying to automate this form filling, you may run into the same steps so hopfully this will serve as a quick guide to troubleshoot the problems you may have run into or to start automating your own form fields.

NOTE: This guide uses Safari but you can use the Chrome actions to complete the same tasks.


Step 1: 🚨 Make sure Javascript can Be Ran FROM System Events 🚨

Ultimately this was the issue I ran into. This setting (off by default prevents rogue applications from taking control of your browser). In most cases this is a great security measure but in our case, it breaks the Keyboard Maestro functionality.

For Safari

With Safari open go to Preferences and select the advanced column.

Check the box Show Develop menu in menu bar

check the box show develop menu in menu bar

In the menu bar select the Develop menu and select the option Allow Javascript from Apple Events.

Enable Javascript from Apple Events

For Chrome

Chrome makes this a little easier. In the menu bar select View, then Develop (already visible) and select Allow Javascript from Apple Events.

In both cases, you will see a check mark that indicates you are ready to Automate!

Step 2: Find the XPath of the field you want to Enter

This is where the magic happens 🧙🏾‍♂️. Finding the right field to target with information can be a challenge as websites come in many different sizes and accesssibility forms.That said you can use the tools built into Keyboard Maestro or the browser to find the correct XPath.

Don't worry too much about what an XPath is. You just need to know how to find it.

Using Keyboard Maestro

In Keyboard Maestro, when you select the Set Safari Field to Text the Safari ˇ will look for forms on the active tab of in your browswer and show all of the input fields available. Find the field that you want to automate with text and select it. Enter the text you wish to fill in.

Choosing the XPath from Keyboard Maestro

NOTE: There is also a checkbox version of this that works exclusively for checkboxes

Using Safari/Chrome

If you have a lot of fields that you want need to identify you can figure out the exact text field you want to add to by right-clicking the field in your browser and selecting Inspect Element (Inspect for Chrome) to view the source code.

inspect element

Then in the inspector you can right click the highlighted code-block and hover over copy and select XPath.

copy XPath

Repeat this step as many times as you like for each field. Finally, add a submit field.

Submit Form