Menu bar icon in OS X for script running as daemon?


Question or issue on macOS:

I have a ruby script( that runs on my macbook as a daemon and monitors a bunch of directories for file changes and rsync any changes that happens. I was wondering would i be able to let it create a icon in the menu bar at the top? Just so that I know it’s actually running, without having to check for it with ps.

Maybe later if needed I might want to be able to control the script from there, simple drop down with stop and status entries, etc.

It seems from ObjectC I can call NSStatusItem to get the icon, but I really just want to do it easily from my Ruby script. Perhaps maybe some applescript call that I can do?

How to solve this problem?

Solution no. 1:

This MacRuby script creates a status bar icon:

So does this one:

Here’s a Gist including code that does it:

# We build the status bar item menu
def setupMenu
  menu =
  menu.initWithTitle 'FooApp'
  mi =
  mi.title = 'Hellow from MacRuby!'
  mi.action = 'sayHello:' = self
  menu.addItem mi

  mi =
  mi.title = 'Quit'
  mi.action = 'quit:' = self
  menu.addItem mi


# Init the status bar
def initStatusBar(menu)
  status_bar = NSStatusBar.systemStatusBar
  status_item = status_bar.statusItemWithLength(NSVariableStatusItemLength)
  status_item.setMenu menu 
  img = 'macruby_logo.png'

# Menu Item Actions
def sayHello(sender)
    alert =
    alert.messageText = 'This is MacRuby Status Bar Application'
    alert.informativeText = 'Cool, huh?'
    alert.alertStyle = NSInformationalAlertStyle
    response = alert.runModal

def quit(sender)
  app = NSApplication.sharedApplication

app = NSApplication.sharedApplication

Solution no. 2:

You could look at MacRuby. It’s a way of developing OS X apps using Ruby instead of Objective-C. It includes a number of improvements, such as getting rid of header files, so yu just have “implementation” files in Ruby. You can use IB for building windows too

Hope this helps!