/ Published in: Ruby
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
SUPPORT = ENV['TM_SUPPORT_PATH'] # Retrieves the path of textmates ruby modules DIALOG = ENV['DIALOG'] # retrieves the tm_dialog command require SUPPORT + '/lib/escape' require SUPPORT + '/lib/osx/plist' # Set up your menu items # Create an array of associative arrays that will hold your menu items # # NOTE: the key names of the associative array are: # title: The menu Title # path: The value that is associated to the selected item # # When you select a menu item tm_dialog retuns both the title and path # of the selected menu item items = [] items << { "title" => "Macs", "path" => "Rule" } items << { "title" => "Windows", "path" => "Stinks" } # Create a container associative array to hold your menu items # # transform an associative array into a plist (Property List, which is just an XML file). to_plist appears # to be an extention that textmate loads up automatically plist = {'menuItems' => items}.to_plist # Run the tm_dialog command and load the result as a parsed property list. # NOTE: e_sh is provided by the escape module. res = OSX::PropertyList::load(`#{e_sh(DIALOG)} -up #{e_sh(plist)}`) # simply display the returned path of the selected menu item puts res['selectedMenuItem']['path']