Create menu bar status icons using BitBar

Sometimes I want to have a persistent notification or indicator generated by Keyboard Maestro. I might use this to have an alert, show that a macro is running, or anything else.

I've started using BitBar for this purpose. BitBar just runs shell scripts and displays their output in your menu bar.

To support this, I've added a this script to my bitbar plugins. It simply concatenates all variables that begin with "bitbar__" and puts them in the menu. I then make heavy use of emoji and custom unicode characters to give myself small notifications in the menu bar.

kmstatus.10s.zip (344 Bytes)

You can do a lot more with BitBar, but this is quick, easy, and fits nicely into any KM macro since it can pull in any number of variables. And if there's no variables of the right name, it just displays nothing.

5 Likes

Wow! I was just wishing I could do something like this. I’ll check it out and see if it’s what I need.

Thanks!

I think this is going to work for my needs! Here's what I did:

  1. I installed BitBar, and selected (created) a folder for the plugins. I put them in Documents/BitBar/Plugins.

  2. I put iNik's applescript in the Plugins folder, but I renamed it to "kmstatus.1d.applescript" so it only runs once a day (I'll explain below).

  3. I created this test macro:

Works great! Setting the variable to an empty string clears the text from the menu bar, but I think there's a slight bug because the icon does't slide over. But if you hover over it, it does, so no biggie.

I have a few things I like to toggle on or off as I need them, and this will tell me at a glance what their state is. Awesome!

1 Like

Ooh! I didn’t see how easy it was to refresh BitBar manually. That’s a
great little improvement!

The resource hit is low enough that it’s probably fine to check all the
time, but your method will refresh immediately when it needs to, and is
more elegant.

Can you figure out how to get a BitBar menu item that runs a KM macro?

I got it to work, sort of. Here’s the plugin:

#!/bin/bash

echo 📀
echo "---"
echo "Enable AutoClose | bash='/Users/Dan/Documents/BitBar/Plugins/KM/MakeMkvEnableAutoClose.sh'"

Here’s the shell script:

osascript -e 'tell app "Keyboard Maestro Engine" to do script "MakeMKV - Enable AutoClose"'

It works, but it leaves the terminal open. If I change the plugin to include “terminal=false”, like this:

#!/bin/bash

echo 📀
echo "---"
echo "Enable AutoClose | bash='/Users/Dan/Documents/BitBar/Plugins/KM/MakeMkvEnableAutoClose.sh' terminal=true"

then it doesn’t work.

Any thoughts?

PS: I had to run this to get the permissions right:

chmod +x KMMakeMkvAutoClose.1d.sh

You can make shell scripts in AppleScript by using osascript in your shebang:

#!/usr/bin/osascript
...your script here`

Here’s what I’ve got that’s working for me:

test.10s.sh:

#!/bin/bash
echo '⎋'
echo '---'
echo 'Trigger Macro |bash="~/bin/kmtrigger.applescript" param1="1E805FC3-73E5-4A2C-AB2B-A17C7E66D76A" terminal=false'`

(This is using the GUID of a macro - I could pass the name, but I’d need a mess of param arguments, this is easier.)

kmtrigger.applescript:

#!/usr/bin/osascript
on run ARGV
   tell application "Keyboard Maestro Engine" to do script ARGV
end run

Is there some reason you cannot put the osascript command directly in the plugin?

iNik - Thanks! That’s what I was missing. I was trying to think along those lines, but I just couldn’t get there.

@peternlewis - I’m not the expert here, but I don’t think BitBar supports that, when “terminal=false” is used. I think it’s a bug. @iNik could answer better.

Peter, it would be really cool if KM supported doing things like this. I suspect it wouldn’t be high on your enhancement list, especially since BitBar can do it. However, it has to intrigue your inner geek/propellerhead, right? Can’t help yourself, right? :stuck_out_tongue_winking_eye:

@peternlewis It requires triggered scripts to be bash one liners, and the way it parses it out doesn’t seem to be friendly to escaped quotes and stuff that AppleScript/osascript demands.

There’s no reason why the plugin itself couldn’t be an AppleScript, but it would still need to output a bash command.

OK, we’re just ignorant or forgetful of the wonderful features available in KM. How about this:

Test Menu Item | href=kmtrigger://macro=BitBarTestMenuItemMacro

-OR-

Test Menu Item | href=kmtrigger://macro=E592D3E7-7FC6-4D5A-B0A0-15D49FE369CB

!!! :open_mouth: :smiley: !!!

1 Like

Hey Dan, it's been a long time that you are using BitBar. I'd like to hear from you if BitBar easy to work with. And if it's possible give us a few examples of what you do with. Ty

I'm not using it anymore. But when I used it, it was pretty easy to use. I don't have any examples other than what's in this thread.

Thanks Dan! I'm happy that you saved my time. :slight_smile: