Skip to content

Instantly share code, notes, and snippets.

@mattetti
Created May 17, 2010 06:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattetti/403462 to your computer and use it in GitHub Desktop.
Save mattetti/403462 to your computer and use it in GitHub Desktop.
framework 'AppKit'
app = NSApplication.sharedApplication
class ItemDelegate
def define_actions(actions)
actions.each do |command|
self.class.send(:define_method, command) do |sender|
puts command
end
end
end
def quit(sender)
exit
end
end
@menu = NSMenu.alloc.init
actions = ['test', 'test2']
menu_delegate = ItemDelegate.new
menu_delegate.define_actions(actions)
actions.each do |action|
item = @menu.addItemWithTitle(action, action: action, keyEquivalent: "")
item.target = menu_delegate
end
item = @menu.addItemWithTitle("Quit", action: 'quit:', keyEquivalent: "q")
item.toolTip = "Click to close this App"
item.target = menu_delegate
bar = NSStatusBar.systemStatusBar.statusItemWithLength(NSSquareStatusItemLength)
bar.title = "test"
bar.menu = @menu
bar.highlightMode = true
app.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment