Keyboard Maestro Blog Posts

July 10, 2018

Execute Shell Script

One of the nice things about https://www.keyboardmaestro.com/main/ is the ability to run Shell Scripts as part of a Macro action. This is useful when you want to apply a clipboard text to a shell script or just to execute a shell command.

Recently I wanted to set up a Status Menu action to simply run a shell script. I am doing some automation work and frequently need to test code changes. it's just easier to have a status menu than to open up a terminal and execute the run command.

Simple Setup

To execute commands, simply use the Bash Shell:

.

Keyboard Maestro Shell Script

Some Notes about Shell Execution

  • You can ignore the output results. (nice feature if you don't need to see the debug information)
  • I have an ampersand after the run_automation.sh so the command would run in the background. There is the ability to run the command asynchronously in Keyboard Maestro.
  • In my execution script, the directory where it's being executed from makes a difference, so I needed to change directory before running the command. I didn't use the 'Script File' method.
  • To run PHP commands you would type in: #!/usr/bin/php

Oh, more thing, if I want to run the command frequently, I can instantly change the macro to be included in the Global Macro Palette. It's a simple switch of the trigger type.

There's a lot of options available, including the ability to pass variables to the shell command. The Keyboard Maestro help section has a lot of detailed information on setting those up.

July 3, 2018

Application Switcher

Keyboard Maestro’s Application Switcher is a very powerful way to navigate between active applications. You can quickly go from one application to the next.

Keyboard Switcher2

A Step Above Apple’s Switcher

What’s separates Keyboard Maestro’s Switcher than Apple:

  • You can have define applications to always appear in the Switcher, making it easy to access applications that you can’t justify having in the Dock.
  • You can exclude applications from showing in the application switcher - even if they are open. This helps cut the clutter.
  • You can open multiple applications. So if your working on a database project, you can open multiple apps at the same time - Such as Terminal and pgAdmin.
  • You can have multiple application switchers so that certain apps only show during certain hours during the day.
  • Keyboard Maestro application switcher is easier to configure.

Using the Application Switcher, you can simply enable the command and then select the application. But there are a few additional commands available.

Some Shortcuts

When the Application Switcher is in focus, keep the Command key and use the mouse and these keys to perform actions:

q Quit Application
k (twice) to mark an application to Force Quit
s Make application hidden
l Mark application to launch (You can select more than one!)
a Hide “Always Show” applications
j Show applications that were recently quit
i Get Information on the selected application

If you accidentally hit the Application Switcher, simply hit the escape key to close it.

Easy Force Quit Feature

I personally like the ‘Force Quit’ feature. It makes it so easy to quit out of an application that is stalled. (Much better than having to remember the keyboard shortcut.

When you see the “beach ball” and it appears the application is stuck, simply activate the application switcher and then kk the application to force quit.

June 26, 2018

BBEdit TextFactory in Keyboard Maestro

Did you know that you can tap into BBedit's TextFactory in Keyboard Maestro?

What is BBEdit's TextFactory?

BBEdit Text Factory is a user-defined set of text command done in a particular order. You can do simple tasks such as Change Case, Sort Lines, and simple search and replace in a particular order that works for your situation.

Why use it in Keyboard Maestro?

The key reason to use TextFactory functionality is that it puts the best of both applications together. You use Keyboard Maestro to define the action, and then let BBEdit do it's work.

Sample TextFactory Action

Zap Gremlins Graphic

Zap Gremlins is a common action that I do with BBEdit. I use it to remove all those smart-quotes and other hidden characters that I don't want to appear in the text.

Sort Lines Graphic

Sorting List is and then Capitalize the words is another common task that I would do in BBEdit.

Both of these are Menu items so that it's easier to invoke them when I need to.

Some Notes

  • Text Factory files are usually stored in ~/Library/Application Support/BBEdit/
  • Double check Keyboard Maestro for some text commands as there are plenty of built in tools that might be easier to do in Keyboard Maestro.
  • Applying a BBEdit Text action will cause Keyboard Maestro to open up BBEdit.
  • Learn more about BBEdit TextFactory

June 19, 2018

Quick Way to Add Actions in Keyboard Maestro

Quickest way to add an action to a Keyboard Maestro Macro is to use Control - Command A

This will bring up a Spotlight like search:

Add KM Action

Type in a word that best describes the action you are looking to add - For example, type 'Chrome' if your looking for action that's around Google Chrome.

After using this for a while, you'll see how this is much better than using the 'Add Action' button in the Macro.

Remember to add an action to a Macro type in: Control Command A.

June 12, 2018

Smart Groups in Keyboard Maestro

Smart Groups in Keyboard Maestro is a way to filter macros based on any search criteria. This works very similar to how Smart Folders work in Finder. Anything you search for can be a smart group.

Legacy Macro Smart Group

Wouldn't it be great to track macros that you're not using? Perhaps these macros are from an old project? It would be handy to know which macros that you're not using to declutter your Keyboard Maestro library.

There's a Smart Group query for that -it's easy to find active Macros that you haven't used in a while. Here's a query that I have set up:

nonuse Macros

Search Query: e: -use:5w

This query basically says, "Show me all active macros that have not been executed in the past 5 weeks.

Here's an alternative version:

Search Query: e: -use:365d

This query basically says, "Show me all active macros that have not been executed in the past year.

Some Other Smart Group Ideas

Here are some other ideas for Smart Groups for Keyboard Maestro:

  • Search Query: %Variable%release - Show macros that are using a certain variable
  • Search Query: curl - Show macros that are using curl
  • Search Query: ?php - Show macros that have PHP scripts enabled

Search Query Help

You can find a list of all the queries on the Keyboard Maestro Help page. There's a lot of cool search queries commands available.

Smart Groups are Great

Keyboard Maestro Smart Groups are a great way to find similar macros. This functionality comes in handy when you need to update a bunch of macros - for example: if you updated a common library file.

June 5, 2018

Keyboard Maestro Macro Library

The Keyboard Maestro Macro library is a good Macro Library where you can some good ideas on Macros to create. Before you spend any time creating a Macro, it's worth looking to see if someone already created one.

Keyboard Macro Library

Type in Command-2 to view the Macro Library. There is a search box on the bottom if you are looking for a certain functionality. Just make sure that "All Entries" category is selected.

Keyboard Macro Library

Online Help

In the Keyboard Maestro forum, you can find additional Macros that people have created. This is a great way to learn about the application and get some ideas on how to use Keyboard Maestro.

There are two Libraries to pick from:

May 29, 2018

Milliseconds to Seconds Converter

This is a quick Macro that will activate when I need to convert the number on the clipboard (Milliseconds) to seconds.

In Action...

I simply select the value, then type in my trigger action keys: .mill then the value gets typed in.

So 23893 will become 0:24 - you can configure this so that it can output whatever format works for you.

Keyboard Maestro Script

Milliseconds

The Javascript that I used for the calculations:

var app = Application.currentApplication()
app.includeStandardAdditions = true
 
var kmInst = app.systemAttribute("KMINSTANCE");
var kmeApp = Application("Keyboard Maestro Engine")
 
var myLocalVar = kmeApp.getvariable("Local__MyVar",  {instance: kmInst});
kmeApp.setvariable("Local__FromJXA", {instance: kmInst, to: "Set in JXA Script"})
function millisToMinutesAndSeconds(millis) {
  var minutes = Math.floor(millis / 60000);
  var seconds = ((millis % 60000) / 1000).toFixed(0);
  return minutes + ":" + (seconds < 10 ? '0' : '') + seconds;
}
millisToMinutesAndSeconds(myLocalVar); // "4:59"

May 22, 2018

Random Keyword

Having a random word comes in handy when you need a word but want to be creative and something more than just 'abc’ or ‘xyz’.

Random Keyword in Keyboard Maestro

Here’s the random keyword macro that I have setup in Keyboard Maestro.

RandomWordPhrases.jpg
Click on image for the full view of the macro.

#!/usr/bin/php
<?php
$words_file = fopen("/usr/share/dict/words","r");
$words_length = filesize("/usr/share/dict/words");


function random_word() {
  global $words_file, $words_length;
  $rand_offset = rand(0,$words_length - $words_length % 1024);
  fseek($words_file, $rand_offset - $rand_offset % 1024, SEEK_SET);
  $words = explode("n", fread($words_file, 1024));
  $rand_word = utf8_decode($words[rand(1, count($words) - 1)]);
  $description = str_replace("'s", "", trim($rand_word));
  return trim(ucfirst($description));
}

echo random_word();
?>

There are many ways to generate a random keyword from the Apple System dictionary file. Using the above PHP method has worked for me. In the above example, I remove any 's in any keywords because they were breaking some testing that I was doing. In addition, the keyword isn't returning any breaking space and the first letter will always be upper case.

A couple of Problems with a Random Keyword

The only problem with this is that the keyword is always random. I have no idea the word is that I used. Well, what if I wanted to remember the last random keyword that I used? (Filename or something.)

That's why Keyboard Maestro comes in handy! In the above example, I have the random keyword set to a variable before it was displayed.

Getting the Last Random Keyword

Here’s a Keyboard Maestro's Macro that I have set up to get the last used random keyword:

Repeat Word Y Y

The Other "Problem"

Every now and again the random keyword generator will echo an inappropriate keyword. The best way around this is to use a different dictionary file.

Easy Way to get a Random Keyword

Whenever I need a random keyword, I type in xx. When I want to recall the last random word generated, I type in yy.These are quick and easy strings that I don't have to worry about accidentally typing.

May 15, 2018

Simple Date Calculation

At my company we do weekly software releases. It's important for everyone to know the date of the next release and Code Freeze.

Here's my simple Keyboard Maestro macro on when the next release will be - we do releases on Thursdays.

Next Release

This is the Unix command that I used: date -v +Thur "+%B %d, %Y"

Two Weeks From Now

I have another macro that shows the release in two week: date -v+2w -vThur "+%B %d, %Y"

Code Freeze Info

Code Freeze is important to know in any release planning. Even though our code freeze hasn't changed much in four years - I still get asked when is code freeze.

That's why I have this macro set up. With it, I can instantly tell anyone how many hours until the next code freeze - without interrupting my current train of thought.

This macro is perfect for slack or as a response to an email inquiry.

I type in... release.info
Keyboard Maestro Response is : The next Code Freeze is at xxx that's xxx hours from now.

Here's the action part of the Macro:

Release Info

I used PHP in this example because it's a lot easier to do the calculation than to have multiple actions. One improvement that I could do would be to use the data from the "Next Release" macro to populate the release date.

Engineering and Product are impressed by how quickly I answer their question. It's as if I am sitting at my computer waiting to give them the answer.

You can see how nice it is to use Keyboard Maestro for repetitive tasks - it's even better when calculations are involved.

May 8, 2018

Slack Based Greeting

Frequently I talk to offshore team members in Slack. The problem that I encounter is that I don't know the time of day its at their location - is it Morning, Afternoon or Night time? So should I say good morning or good evening?

I have a Keyboard Maestro and PHP it makes it real easy to say the proper introduction regardless of where they are in the world.

Real World Example

There is a macro in my library for 'ggi' and this will automatically display the correct greetings when I am talking to my India team in chat. So if it's night time, it would say 'Good Evening' and if it's before 6 pm their time, 'Good Afternoon.' I have similar macros for ggsfo, ggj and ggk .

Now I will always say the correct greetings, I just need to remember where they are located.

This is the PHP code that I use to get that done:
#!/usr/bin/php 
<?php
date_default_timezone_set('Indian/Mauritius');
function greeting(){
    $timeOfDay = date('H');
    if($timeOfDay > '17'){
        return 'Good evening. ';
    } else if ($timeOfDay > '12'){
        return 'Good afternoon. ';
    } else {
        return 'Good morning. ';
    }
}
echo greeting();
?>

You can see the thing that makes the difference is the PHP's date_default_timezone_set function.

This is what the Macro looks like in Keyboard Maestro, your best to use whatever string command works best for you:

India Time Zone

May 1, 2018

Adding Keyboard Short to hide Firefox Bookmark Bar

Firefox doesn't provide a Keyboard Shortcut for Hiding/Unhiding the Bookmark Menu. This is a problem when you want to take a screenshot of the active Firefox window and want to hide the bookmark bar since it may contain information unrelated to the screenshot.

With Keyboard Maestro, you can easily setup a keyboard shortcut by using the "Select or Show a Menu Item" action command. This is a little known Macro action that gives users a lot of flexibility.

Steps to Add a Hot Key to Firefox

To get started, you should create a new Firefox folder to execute macros only when Firefox is the frontmost application. This way you won't trigger the action when running the same command in another application.

Application-Specific Group

  • Create a new Group and Call it Firefox.
  • Make the group available for only Firefox Application.

Fire Fox Group
This is what the Firefox Group should look like. Most people will only have one Firef

New Macro

Simple steps to create the actual Macro:

  • Create a new Macro in the Firefox Group
  • Select the "Select or Show a Menu Item" Action.
  • In the field to right of 'Menu Title' type: View
  • Click on the green '+' to create a Submenu field
  • In the field to right of ' Submenu' type: Toolbars
  • In the field to right of 'Menu Item' type: Bookmark Toolbar

Fire Fox Bookmarkbar
This is what the Keyboard Macro should look like.

What Happens Next

Now you can type in Shift-Command-B to hide the Bookmark Menu in Chrome and Firefox. This is certainly easy to remember and now you don't have to navigate through menus to hide it.

Once you know how to do this, it opens the door to add additional keyboard shortcuts to any other feature within Firefox or other applications.

February 6, 2018

Keyboard Maestro Control

If your using Keyboard Maestro, you should be aware of the the companion iOS App - Keyboard Maestro Control. The app gives you the ability to execute any Keyboard Maestro macro - basically another point of macro execution.

IOS Description

Keyboard Maestro Control is the iOS adjunct to Keyboard Maestro. It allows you to log in to Keyboard Maestro and execute macros from your iPhone, iPod touch or iPad.

You need to ensure that the Keyboard Maestro Web Server is running and configured with a username and password.

Keyboard Promo2018

Ten things I learned

  • There are 11 Macros positions available on the screen - which gives you the ability to have 11 macros visible at any given time.
  • The Macro icon isn't displayed in the App.
  • You can use Emoji to make the line item a bit more visible. Unfortunately, this means you're limited to the icon selection.
  • iOS last update was on July 14, 2014! Still works fine 3.5 years later.
  • The iPhone landscape feature works weirdly and changing the phone from landscape to vertical can cause the App to display 1/2 screen. I fix this by quoting out of the App and restarting. I think this is related to the App being out-of-date by several iOS versions.
  • While you can use any group, after playing with the App, I found having a single group an easy way to manage which macros I want to execute.
  • Most commands I have are easily defined as a typed command, it was difficult to figure out which commands to use in the iOS.
  • The Keyboard Maestro Control app uses the built-in web browser functionality, so it's important to select non-destructive commands.
  • There is no sleep feature, as there is in Quadro, so the screen stays open for a while.
  • Other than connecting to a Keyboard Maestro server, there are no additional settings or configurations.

At the End of the Day..

Dispite the App being out of date, the app still works fine on iOS 11.2.5 (15D60). My complaints are just basic cosmetic changes that would make the application even better.

I would encourage anyone that uses Keyboard Maestro a lot to give it a try. The toughest part is figuring which macros you would want in the app.

January 30, 2018

Add Hyperlink to Clipboard Content

Wouldn't it be great if there was a way to automatically add hyperlinks to common text? Especially when sending emails? For example, if you reference Jira tickets in your email, wouldn't it be nice that they automatically had Hyperlinks?

You can do this using a Keyboard Maestro Macro in a four simple actions.

Creating Macro to Add Hyperlink to Text

To get this done, I am going to use the Unix textutil command. This will help convert an HTML file to Rich Text Format, which will allow the links to show in Mail, Pages, Microsoft Word, or any application supporting RTF format.

The goal of this Macro is to take the content of the clipboard, add hyperlinks, convert to rich text and then put the final product back on the clipboard ready to paste any place. Feel free to customize this to your own needs!

Keyboard Maestro Replace7

In Atlassian Jira, the Software Project name is the first three letters. If your linking up to Jira make sure to match the project name and the company name.

Cool Features to Think About

The nice thing about Keyboard Maestro is that you can add as many Regular Expressions as you want, such as a link to the company website where ever the company name appears.

Known Issues with this Method

Since this is using a temporary file, the data is still stored on the computer after the action is completed. So anyone with computer access can read the contents of the temp file (Simply add a cleanup step at the end to fix this)

When pasting rich text in Mail the text appears to be smaller, that is because the font changes from Helvetica 12 to Times 12.

January 23, 2018

Clipboard History Switcher

Keyboard Maestro and LaunchBar both offer the ability to retrieve previous Clipboard content. Once you enable this feature, you'll find it very useful to get back old clipboard content.

The Clipboard History feature is a pretty powerful function in both applications. Here's a general overview of the differences between the two.

Website Descriptions

Description from Stairways Software:

Clipboard History Switcher saves a copy of each clipboard every time you copy something. You can then paste any previous system clipboard by triggering the Clipboard History Switcher macro. Clipboard History Switcher will present you with a window allowing you to select any of the past clipboards and paste them.

Description from LaunchBar:

LaunchBar's Clipboard History preserves the data of your most recent Copy operations, allowing you to use the copied objects again later.

You can have both LaunchBar and Keyboard Maestro Clipboard History running at the same time - you just need to use different Keyboard shortcuts.

Here's a snapshot of the two windows side-by-side. See how helpful Keyboard Maestro version is with images in the clipboard:

Clipboard History

Five Key Differences between the Two Applications

  • Content Display - Keyboard Maestro gives you a nice preview of any images in the clipboard, whereas LaunchBar only shows an image icon, the dimensions and the application where the image was the clip from.
  • Combine Content Functionality - LaunchBar has a Double-Copy functionality that combines the current copy content with the previous copied content.
  • Favorite Clips - In Keyboard Maestro, You can save clip content as a favorite so it doesn't disappear from the Switcher.
  • Search Capabilities - Keyboard Maestro allows you to search the Clipboard Switcher making it easy to find previously copied text.
  • Display Limits - Keyboard Maestro last two hundred times you have copied something to the System Clipboard. With LaunchBar you can set the duration to be 10, 20, 30, 40, 100 items or by number of days... 1,2, or 3 day or a week.

January 16, 2018

Computer External IP Address

Using Keyboard Maestro and AppleScript it's really easy to quickly display the computer's external IP address. This is similar to functionality that I created using TextExpander.

Using Keyboard Maestro, users have a lot more control. In this updated version of the script, I can display the IP address to the screen in large letters, and add it to the clipboard - ready to paste it where ever needed.

You can modify this any way you want to fit your needs.

Execute the Apple Script

The first step is to execute the AppleScript and set the results to a variable:

Setup My IP1

Code used:

(*
Credit to www.applehelpwriter.com*
*)*
set myTemp to do shell script "mktemp -t txt"*
do shell script "curl -s http://checkip.dyndns.org &> " & myTemp & " &2> /dev/null"*
# CHANGE THE DELAY HERE... *
delay 3*
set extIP to do shell script "sed 's/[a-zA-Z/<> :]//g' " & myTemp

Display the Results to Screen

Use Keyboard Maestro's large text display and show the IP address on the screen:

Setup My IP2

Add to Clipboard

Add the IP address to the clipboard in case I need to paste the information into a working document.

Setup My IP3