Use TextMate's tm_dialog command to create user defined menus


/ Published in: Ruby
Save to your folder(s)



Copy this code and paste it in your HTML
  1. SUPPORT = ENV['TM_SUPPORT_PATH'] # Retrieves the path of textmates ruby modules
  2. DIALOG = ENV['DIALOG'] # retrieves the tm_dialog command
  3.  
  4. require SUPPORT + '/lib/escape'
  5. require SUPPORT + '/lib/osx/plist'
  6.  
  7. # Set up your menu items
  8. # Create an array of associative arrays that will hold your menu items
  9. #
  10. # NOTE: the key names of the associative array are:
  11. # title: The menu Title
  12. # path: The value that is associated to the selected item
  13. #
  14. # When you select a menu item tm_dialog retuns both the title and path
  15. # of the selected menu item
  16.  
  17. items = []
  18. items << {
  19. "title" => "Macs",
  20. "path" => "Rule"
  21. }
  22.  
  23. items << {
  24. "title" => "Windows",
  25. "path" => "Stinks"
  26. }
  27.  
  28. # Create a container associative array to hold your menu items
  29. #
  30. # transform an associative array into a plist (Property List, which is just an XML file). to_plist appears
  31. # to be an extention that textmate loads up automatically
  32. plist = {'menuItems' => items}.to_plist
  33.  
  34. # Run the tm_dialog command and load the result as a parsed property list.
  35. # NOTE: e_sh is provided by the escape module.
  36. res = OSX::PropertyList::load(`#{e_sh(DIALOG)} -up #{e_sh(plist)}`)
  37.  
  38. # simply display the returned path of the selected menu item
  39. puts res['selectedMenuItem']['path']

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.