This is a tutorial for how to use KM and BitBar ( https://github.com/matryer/bitbar ) to add an icon to your OS/X Menu Bar - a dynamically-generated icon and drop-down menu.
-
Install BitBar. Remember that when you install it, it opens a dialog asking for the folder to put Plugins in. Create a folder and select it.
-
Import my macros. There’s 3.
Set BitBarMenuExample.kmmacros (11.5 KB)
- Edit the macro named “_Setup Example !!!DO FIRST!!!”, and change the path to the plugin - the plugin will be created for you, but change the path first.
-
Run “_Setup Example !!!DO FIRST!!!”. You can select all the actions and click the “try” button, or if there’s a better way, go for it. This will create the plugin script file.
-
You should now have a “bell” icon in your Menu Bar. Click it and a menu will drop down. If you click “Example Menu Item”, it will call my example macro.
-
Change the Icon and/or menu text in the macro "Set BitBarMenuExample__Script", then re-run it (it's is in the KM status menu). Check out the results.
Here’s the details of how this works:
Plugin File
You can read up on the details of the BitBar plugin format, but this is our plugin file, called “DanTimer.30s.applescript” unless you changed it. The “.30s.” portion means BitBar should refresh it every 30 seconds.
#!/usr/bin/osascript
set AppleScript's text item delimiters to {" "}
tell application "Keyboard Maestro Engine" to getvariable "BitBarMenuExample__Script"
It’s an AppleScript script that gets the contents of the Plugin (i.e. the Icon and Menu Bar) from the KM variable “BitBarMenuExample__Script”.
So every 30 seconds, it asks KM for that variable, and it becomes the icon and menu.
Our Dynamic Menu Script
Here’s what we’re generating in KM for the Plugin script:
- The first line is the icon - it’s actually text, but we’re using an Emoji for the icon.
- The three dashes say “the next is a menu”.
- The menu line has the menu text before the |, and after it is an href that tells KM to execute the macro.
We can change this variable at any time, and when BitBar refreshes, the icon and menu will change.
Closing
Hopefully this all makes sense. If not, let me know. Have fun!
PS: This took me a while to set up, so if there's issues, please let me know - I want to get it right.