Skip to content

Instantly share code, notes, and snippets.

@rjsamson
Created May 27, 2013 01:50
Show Gist options
  • Save rjsamson/5654795 to your computer and use it in GitHub Desktop.
Save rjsamson/5654795 to your computer and use it in GitHub Desktop.
Example Rubymotion menubar app
class AppDelegate
def applicationDidFinishLaunching(notification)
buildStatus(setupMenu)
end
def buildStatus(menu)
@statusBar = NSStatusBar.systemStatusBar
@item = @statusBar.statusItemWithLength(NSVariableStatusItemLength)
@item.retain
@item.setTitle("Menubar App")
@item.setHighlightMode(true)
@item.setMenu(menu)
end
def setupMenu
menu = NSMenu.new
menu.initWithTitle 'Menubar App'
mi = NSMenuItem.new
mi.title = 'Hello!'
mi.action = 'sayHello:'
menu.addItem mi
mi = NSMenuItem.new
mi.title = 'Quit'
mi.action = 'terminate:'
menu.addItem mi
menu
end
def sayHello(sender)
alert = NSAlert.new
alert.messageText = 'This is Rubymotion Status Bar Application'
alert.informativeText = 'Cool, huh?'
alert.alertStyle = NSInformationalAlertStyle
alert.addButtonWithTitle("Yeah!")
response = alert.runModal
end
end
# -*- coding: utf-8 -*-
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project/template/osx'
Motion::Project::App.setup do |app|
# Use `rake config' to see complete project settings.
app.name = 'MenubarApp'
app.info_plist['NSUIElement'] = 1
end
@gmanley
Copy link

gmanley commented Oct 19, 2013

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment