이 세상에 하나는 남기고 가자

이 세상에 하나는 남기고 가자

세상에 필요한 소스코드 한줄 남기고 가자

BitBar 소개 - OS X Menu Bar에 원하는 모니터링 정보 넣기

유영재

BitBar 를 사용하면 Mac OS X 메뉴 막대에 모든 스크립트나 프로그램의 출력을 넣을 수 있다. 이미 BitBar 사이트에서 제공하고 있는 다양한 플러그인이 존재하지만 출력 결과에 대한 규칙만 지킨다면 어떤 내용이라도 들어갈 수 있으므로 다양한 분야에 활용할 수 있다.

나의 경우는 서버 또는 서비스의 상태를 모니터링 하거나 구글 어날리틱스, 애드센스 등의 현황을 Menu Bar에서 바로 확인하기 위해 사용한다. 하지만 앞서 이야기한 것처럼 활용에 제한이 없으므로 자신이 모니터링하고자하는 모든 정보를 만들어 추가할 수 있다(게다가 간단하다).


설치

  • https://github.com/matryer/bitbar/releases 에 가서 최신 버전을 다운 받는다.
    • BitBar 와 BitBarDistro 가 있는데 그냥 BitBar를 다운 받으면 된다.
  • 압축을 풀어서 응용 프로그램 폴더에 넣고 실행한다.

플러그인 설치

BitBar에 표시되는 내용은 플러그인에서 출력한 결과들이므로 원하는 정보를 출력해 줄 플러그인들이 필요하다.
플러그인의 설치는 간단하다. 지정된 플러그인 폴더에 원하는 플러그인 파일을 넣고 메뉴에서 'Refresh' 를 실행하면 된다.

BitBar는 플러그인을 실행해서 결과를 출력해주므로 해당 플러그인들은 실행 권한을 가지고 있어야 한다.

chmod +x plugin.sh

플러그인 폴더의 위치를 확인하거나 변경하려면 Preferences 하위의 메뉴에서 원하는 메뉴를 고르면 된다.

bitbar-os-x-menu-bar-app

플러그인 갱신 시간 설정

플러그인 실행 결과에 대한 갱신 시간은 플러그인의 파일 이름에 아래의 형식을 사용함으로써 지정 가능하다.

{name}.{time}.{ext}

  • name - 파일명
  • time - 새로 고침 빈도
    • 10s - ten seconds
    • 1m - one minute
    • 2h - two hours
    • 1d - a day
  • ext - 파일 확장명

예를들어 date.1m.sh 플러그인은 1분 간격으로 실행되어 출력된 결과로 갱신된다.

플러그인 만들기

이미 만들어진 플러그인을 사용한 것뿐 아니라 Plugin API를 이용해서 원하는 플러그인을 직접 만들 수도 있다.

  • 표준 출력을 사용하는 실행 가능한 스크립트 형식을 작성하는 것으로 플러그인을 만들 수 있다.
    • 스크립트에서 사용하는 언어는 ruby, python php, bash 등 사용하는 시스템에서 사용 가능한 어떠한 언어도 사용할 수 있다.
  • 여러 줄이 반복해서 출력할 수 있다.
  • ---만으로 구성된 행이 있으면 그 아래의 행은 해당 플러그인의 드롬 다운에 표시되지만 메뉴 표시 줄 자체에는 나타나지 않는다.
  • --로 시작하는 줄은 하위 메뉴로 나타난다.
  • | 를 이용해서 해당 줄에 여러가지 정보를 포함할 수 있다.
    • href=.. to make the item clickable
    • color=.. to change their text color. eg. color=red or color=#ff0000
    • font=.. to change their text font. eg. font=UbuntuMono-Bold
    • size=.. to change their text size. eg. size=12
    • bash=.. to make the item run a given script terminal with your script e.g. bash=/Users/user/BitBar_Plugins/scripts/nginx.restart.sh if there are spaces in the file path you will need quotes e.g. bash="/Users/user/BitBar Plugins/scripts/nginx.restart.sh"
    • param1= to specify arguments to the script. additional params like this param2=foo param3=bar full example bash="/Users/user/BitBar_Plugins/scripts/nginx.restart.sh" param1=- verbose assuming that nginx.restart.sh is executable or bash=/usr/bin/ruby param1=/Users/user/rubyscript.rb param2=arg1 param3=arg2 if script is not executable
    • terminal=.. start bash script without opening Terminal. true or false
    • refresh=.. to make the item refresh the plugin it belongs to. If the item runs a script, refresh is performed after the script finishes. eg. refresh=true
    • dropdown=.. May be set to true or false. If false, the line will only appear and cycle in the status bar but not in the dropdown
    • 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. eg. length=10
    • trim=.. whether to trim leading/trailing whitespace from the title. true or false (defaults to true)
    • alternate=true to mark a line as an alternate to the previous one for when the Option key is pressed in the dropdown
    • templateImage=.. set an image for this item. The image data must be passed as base64 encoded string and should consist of only black and clear pixels. The alpha channel in the image can be used to adjust the opacity of black content, however. This is the recommended way to set an image for the statusbar. Use a 144 DPI resolution to support Retina displays. The imageformat can be any of the formats supported by Mac OS X
    • image=.. set an image for this item. The image data must be passed as base64 encoded string. Use a 144 DPI resolution to support Retina displays. The imageformat can be any of the formats supported by Mac OS X
    • emojize=false will disable parsing of github style :mushroom: into 🍄
    • ansi=false turns off parsing of ANSI codes.

아래는 matryer/bitbar 에 소개된 예시들이다. 예시들을 보면 알겠지만 자신이 익숙한 언어와 BitBar API를 사용해서 간단히 만들 수 있다.

One line plugin

#!/bin/bash
date

Multi-line plugin

#!/bin/bash

# the current date and time
date

# the current username
echo $USER

# the current user id
id -u

Multi-line plugin with extra data

#!/bin/bash
echo "One"
echo "Two"
echo "Three"
echo "---"
echo "Four"
echo "Five"
echo "Six"
  • Only One, Two and Three will appear in the top bar
  • Clicking the plugin menu item will show all lines

Multi-line plugin with links and colors

#!/bin/bash
curl -m 1 http://example.com -I >/dev/null 2>&1
[ $? -gt 0 ] && echo "FAIL | color=red" || echo "OK | color=green"
echo "---"
echo "Show Graphs | color=#123def href=http://example.com/graph?foo=bar"
echo "Show KPI Report | color=purple href=http://example.com/report"
comments powered by Disqus