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

MacOS

Question or issue on macOS:

I have a ruby script(https://github.com/daemonza/MacBak) 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:
https://github.com/ashchan/gmail-notifr

So does this one:
https://github.com/isaac/Stopwatch

Here’s a Gist including code that does it:
https://gist.github.com/1480884

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

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

  menu
end

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

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

def quit(sender)
  app = NSApplication.sharedApplication
  app.terminate(self)
end

app = NSApplication.sharedApplication
initStatusBar(setupMenu)
app.run

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!