這MacRuby的腳本創建一個狀態欄圖標:
https://github.com/ashchan/gmail-notifr
那麼,這一個:
https://github.com/isaac/Stopwatch
這裏的要點包括代碼,做它:
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
看看RubyCocoa。我從來沒有使用它,但我認爲從Ruby使用Cocoa非常有效。 – Linuxios 2012-04-19 13:08:47
@Linux_iOS看到[這個答案](http://stackoverflow.com/a/695353/405017)注意RubyCocoa是過去,而MacRuby是未來。 – Phrogz 2012-04-19 16:08:32
嗯。我從來沒有處理過,所以我不知道。感謝澄清。 – Linuxios 2012-04-19 23:06:50