Mynu
A simple DSL to create a systembar menu with macruby in OSX
gem install mynu
macruby examples/dsl.rb
Usage example:
macruby examples/dsl.rb
require 'rubygems'
require 'mynu'
mynu = Mynu.new
mynu. "Hello World!" do ||
puts "Inside menu setup!"
.title = "Good Bye World!"
.item "Option 1" do |item|
item.execute do
puts "Execution block"
item.title = "Dynamically changed!"
end
end
. "Option 2" do ||
.item "Option 2a" do
puts "Option 2a clicked!"
end
.item "Option 2b" do
puts "Option 2b clicked!"
end
.execute do
puts "Menu item clicked!"
.title = "Dynamically changed!"
end
end
= .item "Disabled" do |item|
item.disabled
end
.item "Enable `Disabled`" do |item|
item.execute do
.enabled
.execute do
.title = "Disabled (Again)!"
.disabled
end
end
end
end
mynu.item "Simple Item" do
puts "Hello World!"
end
mynu.run
====
A workflow example:
macruby examples/workflow.rb
mynu = Mynu.new
mynu. "Applications" do |applications|
applications.app "TextEdit", "/Applications/Utilities/Terminal.app"
end
mynu. "Project" do |project|
project.link "Live", "http://example.com"
project.link "Staging", "http://user:[email protected]"
project.link "Development", "http://example.dev"
project. "Repos" do |repos|
repos.open "Example", "~/example"
repos.open "Resources", "~/example-resources"
end
end
mynu.separator
mynu. "Development" do |development|
development. "Rails" do |rails|
rails.link "Github", "http://github.com/rails/rails"
rails.open "Repo", "~/workspace/rails"
end
end
mynu.separator
mynu.open "Downloads", "~/Downloads"
mynu.separator
mynu.open "Desktop", "~/Desktop"
mynu.separator
mynu.run
A terminal example (best used with Visor and one terminal window!):
macruby examples/terminal.rb
require 'rubygems'
require 'mynu'
mynu = Mynu.new
#############################################################
# Warning!
#
# This makes the assumation you use Visor and only manage
# one terminal window. Otherwise tabs will only be created
# in your first/primary terminal window.
#
# You can get Visor at: http://visor.binaryage.com/
#
#############################################################
# Normal usage will return to the frontmost app at execution
mynu.terminal "Echo & Disable Item", "echo hello" do
disabled
end
mynu.terminal "Echo & Exit", "echo hello", :exit => true do
disabled
end
mynu.terminal "Keeps focus on Terminal Tab", "echo hello", :focus => true do
disabled
end
mynu.run
Todo
- Improved API (done!)
- Reloading?
- Crash Handling?
- FileMenuItem
- Simple Dialogs