Guest User

Untitled

a guest
May 25th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. framework 'AppKit'
  2.  
  3. app = NSApplication.sharedApplication
  4.  
  5. class ItemDelegate
  6.  
  7. def define_actions(actions)
  8. actions.each do |command|
  9. self.class.send(:define_method, command) do |sender|
  10. puts command
  11. end
  12. end
  13. end
  14.  
  15. def quit(sender)
  16. exit
  17. end
  18.  
  19. end
  20.  
  21. @menu = NSMenu.alloc.init
  22. actions = ['test', 'test2']
  23. menu_delegate = ItemDelegate.new
  24. menu_delegate.define_actions(actions)
  25.  
  26. actions.each do |action|
  27. item = @menu.addItemWithTitle(action, action: action, keyEquivalent: "")
  28. item.target = menu_delegate
  29. end
  30.  
  31. item = @menu.addItemWithTitle("Quit", action: 'quit:', keyEquivalent: "q")
  32. item.toolTip = "Click to close this App"
  33. item.target = menu_delegate
  34.  
  35. bar = NSStatusBar.systemStatusBar.statusItemWithLength(NSSquareStatusItemLength)
  36. bar.title = "test"
  37. bar.menu = @menu
  38. bar.highlightMode = true
  39.  
  40. app.run
Add Comment
Please, Sign In to add comment