Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment