An If Then Else Macro with Keyboard Maestro

Difficulty: Normal

Do you find data entry as annoying and boring as I do? It doesn’t have to be that way. Try this Keyboard Maestro script to make those simple boring tasks more manageable and perhaps even fun.

Of course, you could apply this to any context, but I chose to use the example of entering a client’s contact information into a Pages document. (Actually, I prefer Apple’s Text Edit or any third party app capable of plain text editing, but that’s a topic for another post)

Although this isn’t a complicated script to write, there a many places where things can go wrong. I find this script is a springboard to bigger and better things. It incorporates an essential step, the If Then Else script step, which when mastered, can take your productivity as far as you want.

Let’s start with the User Prompt:

Setting Up the User Prompt
Setting Up the User Prompt

As always, you can tailor this to your needs: exercise routines, diet results, client info, DVD library, etc. You can get clarity on the Paid Status value here on a previous post.

The next step. You have the data, now you open your preferred text editor. I place pauses immediately after the computer needs to do some work or animation; we want the computer to finish this step before our next step triggers, so it’s important you get this right. Too long is better than too short a time span. Once it’s working perfectly, you can always fine tune the timing later.

In this example, I open Apple’s Pages app, use a keyboard shortcut to open a new file, and use the return keystroke to simulate clicking OK. This works fine for Pages, it may be too much for other text editors. In other words, you’ll need to make it fit:

Pages Related Macros

The next step is the data entry. Do not get intimidated here. You do not need to know this code-looking syntax. I enter the text ‘First Name: ‘ then click the disclosure triangle next to ‘Insert Token’, above the text box to the right. There you can hover over the first item on the list, ‘Variable’ and find the variables you named in the first step there. It will automatically insert this ‘code’ for you.

As a side note: I have so many variables, I sometimes click the wrong variable. Double check you’ve chosen the right one.

Then comes the If Then Else Script step. It’s actually very easy. The hardest part is deciding on the trigger. In this example, I use the value of ‘Paid Status’: if ‘Paid Status’ is true, do this… and if Paid Status is false, then do this…

Entering Text Macro

 

If everything went well, when you press your keyboard shortcut to activate this script, you should see the following:

 

empty user prompt
empty user prompt

Enter some text:

with the prompt filled out
with the prompt filled out

Then watch Keyboard Maestro‘s magic wand do it’s work!

What it should look like
What it should look like

Those most common misstep for me, other than the ones I mentioned, is proper formatting: sometimes there’s a carriage return or a space missing or a return where one isn’t needed. These are minor details. The most common problem I have is managing the pause length, but with a simple script like this, you shouldn’t have any problems.

Other options you can try:

  • take out the steps that open an app and trigger the script when you’re already in your preferred app
  • add more complicated variables
  • add calculations
  • create sentences with the user input and then print that to your document
  • this list is limitless

Have fun with this. I hope you create same really productive scripts.

 

  • Pingback: Derrick()

    • The Boss

      спасибо за чтение (thanks Google translate) or thanks for reading.