BitBar PHP Formatter

Open source formatter for Bitbar. Display anything in Mac's menu bar.

  • 3rd February 2016

Earlier this month I came across BitBar on GitHub. BitBar puts the output from any script in the Mac OS X menu bar. More importantly however, BitBar supports a range of formatting options, turning each script into its own useful utility.

BitBar example

BitBar is powered by plugins, most of these being bash scripts. While bash scripts can be very versatile and powerful, I personally, can get a lot more done using PHP. I'd rather spend time writing the logic and pulling in data from various sources, than worrying about using the right syntax for BitBar.

Because of this, I've created and open sourced a simple PHP formatter library for BitBar! bitbar-php has support for the majority of the formatting options supported by BitBar, including:

  • href to make the dropdown items clickable
  • color to change the text color.
  • font to change the text font.
  • size to change the text size.
  • length to truncate the line to the specified number of characters. A will be added to any truncated strings, as well as a tooltip displaying the full string.
  • trim whether to trim leading/trailing whitespace from the title.

Support for bash, refresh, dropdown and terminal will be added soon.

Installing

Currently, BitBar reads any file in your plugins directory as a script and tries to execute it. To workaround this, create a hidden folder beginning with a dot, for example .bitbar/. In this directory create or edit your composer.json to include the library:

{
  "require": {
    "steveedson/bitbar-php": "dev-master"
  }
}

or run $ composer require "steveedson/bitbar-php"

Usage

#!/usr/bin/php

<?php

require ".bitbar/vendor/autoload.php";

use SteveEdson\BitBar;

// Create BitBar formatter
$bb = new BitBar();

// Create the first line
$line = $bb->newLine();

// Set the text and formatting
$line
    ->setText("Hello World")
    ->setColour("yellow")
    ->setUrl("https://steveedson.co.uk")
    ->show();

At the time of writing, there isn't a single PHP plugin available on the BitBar website, hopefully this library will help change that.

Ideas

Need some ideas of what to create? How about the following:

  • Using johngrogg/ics-parser to read Google Calendars to create a Schedule view.
  • Using briannesbitt/Carbon to create a countdown timer or clock.
  • Monitor EC2 instances, SSHing to them when clicked (this would be a great replacement to Elastics which has been discontinued)
  • View Stripe statistics using the Stripe SDK

If this project is useful to you, or you think you can help improve it, please star the project on GitHub or submit a pull request.