public
Last active

MacRuby StatusBar Application

  • Download Gist
MacRuby StatusBar App
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#
# Initialize the stuff
#
# 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
 
# Rock'n Roll
app = NSApplication.sharedApplication
# Create the status bar item, add the menu and set the image
initStatusBar(setupMenu)
app.run

Just in case somebody is wondering add: framework 'AppKit' tu run it
The icon will be blank unless you name some pic on that directory macruby_logo.png

Thanks for the gist

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.