require 'hotcocoa'
module CustomViewBehaviors
  def redraw
    needsDisplay = true
  end
  def drawRect(rect)
    @frame_image ||= NSImage.imageNamed("frame.png")
    @frame_image.drawAtPoint([0,0], fromRect:frame,
        operation:NSCompositeSourceOver, fraction:1.0)
    window.invalidateShadow
  end
end
module CustomWindowBehaviors
  def initWithContentRect(contentRect,
      styleMask:aStyle,backing:bufferingType,defer:flag)
    super(contentRect,aStyle,NSBackingStoreBuffered,false)
  end
  def canBecomeKeyWindow
    true
  end
  def mouseDragged(theEvent) #move the window with drag
    cur = loc(mouseLocationOutsideOfEventStream, @start)
    new_origin = NSPoint.new(cur.x, cur.y)

    screen = NSScreen.mainScreen.frame
    new_origin.y = [new_origin.y,
      screen.origin.y+screen.size.height-frame.size.height
      ].min
    self.frameOrigin = new_origin
  end
  def mouseDown(evt) #drag start
    @start = loc(evt.locationInWindow, frame.origin)
  end
  def loc(src1,offset)
    loc=convertBaseToScreen(src1)
    loc.x -= offset.x ; loc.y -= offset.y
    loc
  end
end
class Application
  include HotCocoa
  FULL={:expand => [:width,:height]}
  def start
    application :name => "Report Bug" do |app|
      app.delegate = self
      @main_window = window(:frame => [450,300,128,128],
      :level=>NSStatusWindowLevel,:style=>[:borderless],
      :alphaValue=>0.8,:opaque=>false,:hasShadow=>true
      ) do |win|
        win.setBackgroundColor(color(:name => 'clear'))
        win.extend(CustomWindowBehaviors)
        win.contentView.extend(CustomViewBehaviors)

        win  FULL,
          :frame => [0, 0, 42, 42]) do |view|
          view :recessed,:title=>title,:on_action=>act,
      :layout => {:expand=>[:width],:start => false})
  end  
  def sayit
    alert :message => "put your stuff here"
  end
end
Application.new.start

require 'hotcocoa'
module CustomViewBehaviors
  def redraw
    needsDisplay = true
  end
  def drawRect(rect)
    @frame_image ||= NSImage.imageNamed("frame.png")
    @frame_image.drawAtPoint([0,0], fromRect:frame,
        operation:NSCompositeSourceOver, fraction:1.0)
    window.invalidateShadow
  end
end
module CustomWindowBehaviors
  def initWithContentRect(contentRect,
      styleMask:aStyle,backing:bufferingType,defer:flag)
    super(contentRect,aStyle,NSBackingStoreBuffered,false)
  end
  def canBecomeKeyWindow
    true
  end
  def mouseDragged(theEvent) #move the window with drag
    cur = loc(mouseLocationOutsideOfEventStream, @start)
    new_origin = NSPoint.new(cur.x, cur.y)

    screen = NSScreen.mainScreen.frame
    new_origin.y = [new_origin.y,
      screen.origin.y+screen.size.height-frame.size.height
      ].min
    self.frameOrigin = new_origin
  end
  def mouseDown(evt) #drag start
    @start = loc(evt.locationInWindow, frame.origin)
  end
  def loc(src1,offset)
    loc=convertBaseToScreen(src1)
    loc.x -= offset.x ; loc.y -= offset.y
    loc
  end
end
class Application
  include HotCocoa
  FULL={:expand => [:width,:height]}
  def start
    application :name => "Report Bug" do |app|
      app.delegate = self
      @main_window = window(:frame => [450,300,128,128],
      :level=>NSStatusWindowLevel,:style=>[:borderless],
      :alphaValue=>0.8,:opaque=>false,:hasShadow=>true
      ) do |win|
        win.setBackgroundColor(color(:name => 'clear'))
        win.extend(CustomWindowBehaviors)
        win.contentView.extend(CustomViewBehaviors)

        win  FULL,
          :frame => [0, 0, 42, 42]) do |view|
          view :recessed,:title=>title,:on_action=>act,
      :layout => {:expand=>[:width],:start => false})
  end  
  def sayit
    alert :message => "put your stuff here"
  end
end
Application.new.start

#!/usr/bin/env macruby
#create a bug ticket from the current email
#tweaked CGI::escape
def escape(string)
  string.gsub(/([^ a-zA-Z0-9_.-]+)/) do
    $1.nil? ? nil : ('%' + $1.unpack('H2' * $1.bytesize).
      compact.join('%').upcase)
  end.tr(' ','+')
end

framework 'ScriptingBridge'
mail = SBApplication.applicationWithBundleIdentifier(
  'com.apple.mail')
mail.selection.each do |msg|
  params=[[:summary,msg.subject.chomp],
    [:description,msg.content.get.chomp]]
  url= "https://trac.company.com/newticket?"+
    (params.collect{ |n,v| "#{n}=#{escape(v)}"}.join('&'))
  NSWorkspace.new.openURL(NSURL.URLWithString(url))
end
#thanks to @lrz for help here

#!/usr/bin/env macruby
#create a bug ticket from the current email
#tweaked CGI::escape
def escape(string)
  string.gsub(/([^ a-zA-Z0-9_.-]+)/) do
    $1.nil? ? nil : ('%' + $1.unpack('H2' * $1.bytesize).
      compact.join('%').upcase)
  end.tr(' ','+')
end

framework 'ScriptingBridge'
mail = SBApplication.applicationWithBundleIdentifier(
  'com.apple.mail')
mail.selection.each do |msg|
  params=[[:summary,msg.subject.chomp],
    [:description,msg.content.get.chomp]]
  url= "https://trac.company.com/newticket?"+
    (params.collect{ |n,v| "#{n}=#{escape(v)}"}.join('&'))
  NSWorkspace.new.openURL(NSURL.URLWithString(url))
end
#thanks to @lrz for help here

require 'hotcocoa'
framework 'webkit'
class Application
  include HotCocoa
  FULL={:expand => [:width,:height]}
  BASE=<<-END
    <html><head><style type="text/css">
    * { font-family: Monaco; }
    </style><script type="text/javascript">
    function say(arg) { window.TheBridge.click(arg);}
    </script>
    </head><body><h3>Ruby JavaScript Bridge</h3>
    <a href="#" onclick="say('hi')">tell</a></body></html>
  END
  def click(arg) #called from javascript
    root = document.createElement("div");
    root.innerHTML="javascript tells ruby: #{arg}"
    document.body.appendChild(root)
  end
  def document
    @web_view.mainFrame.DOMDocument
  end
  def self.webScriptNameForSelector(sel) #hide : in name
    sel.to_s.sub(/:$/,'') if is_available_selector?(sel)
  end
  def self.isSelectorExcludedFromWebScript(sel)
    ! is_available_selector?(sel)
  end
  def self.isKeyExcludedFromWebScript(key)
    true
  end
  def self.is_available_selector?(sel)
    ['click:'].include?(sel.to_s)
  end
  def start
    application :name => "MyBridge" do |app|
      app.delegate = self
      window :title => "MyBridge",
        :frame => [10, 620, 330, 230] do |win|
        win << @web_view=web_view(:layout => FULL) do |wv|
          wv.mainFrame.loadHTMLString BASE, baseURL: nil
          wv.frameLoadDelegate=self
          wso=wv.windowScriptObject #make visible to JS
          wso.setValue(self, forKey:"TheBridge")
        end
        win.will_close { exit }
      end
    end
  end
end
Application.new.start

require 'hotcocoa'
framework 'webkit'
class Application
  include HotCocoa
  FULL={:expand => [:width,:height]}
  BASE=<<-END
    <html><head><style type="text/css">
    * { font-family: Monaco; }
    </style><script type="text/javascript">
    function say(arg) { window.TheBridge.click(arg);}
    </script>
    </head><body><h3>Ruby JavaScript Bridge</h3>
    <a href="#" onclick="say('hi')">tell</a></body></html>
  END
  def click(arg) #called from javascript
    root = document.createElement("div");
    root.innerHTML="javascript tells ruby: #{arg}"
    document.body.appendChild(root)
  end
  def document
    @web_view.mainFrame.DOMDocument
  end
  def self.webScriptNameForSelector(sel) #hide : in name
    sel.to_s.sub(/:$/,'') if is_available_selector?(sel)
  end
  def self.isSelectorExcludedFromWebScript(sel)
    ! is_available_selector?(sel)
  end
  def self.isKeyExcludedFromWebScript(key)
    true
  end
  def self.is_available_selector?(sel)
    ['click:'].include?(sel.to_s)
  end
  def start
    application :name => "MyBridge" do |app|
      app.delegate = self
      window :title => "MyBridge",
        :frame => [10, 620, 330, 230] do |win|
        win << @web_view=web_view(:layout => FULL) do |wv|
          wv.mainFrame.loadHTMLString BASE, baseURL: nil
          wv.frameLoadDelegate=self
          wso=wv.windowScriptObject #make visible to JS
          wso.setValue(self, forKey:"TheBridge")
        end
        win.will_close { exit }
      end
    end
  end
end
Application.new.start

--sorry applescript today
set status to "start"
my growlRegister()
try
  set result to do shell script "sudo apachectl " &amp; ¬
    status with administrator privileges
  my growlNotify(status &amp; "ing apache", result)
on error errmsg
  my growlNotify("error", errmsg)
end try
--  end process text
--end using terms from

using terms from application "GrowlHelperApp"
  -- Register Growl
  on growlRegister()
    tell application "GrowlHelperApp"
      register as application ¬
        "GrowlHelperApp" all notifications {"Alert"} ¬
        default notifications {"Alert"} ¬
        icon of application "GrowlHelperApp.app"
    end tell
  end growlRegister
  
  -- Notify using Growl 
  on growlNotify(grrTitle, grrDescription)
    tell application "GrowlHelperApp"
      notify with name "Alert" title grrTitle ¬
        description grrDescription ¬
        application name "GrowlHelperApp"
    end tell
  end growlNotify
end using terms from

--sorry applescript today
set status to "start"
my growlRegister()
try
  set result to do shell script "sudo apachectl " & ¬
    status with administrator privileges
  my growlNotify(status & "ing apache", result)
on error errmsg
  my growlNotify("error", errmsg)
end try
--  end process text
--end using terms from

using terms from application "GrowlHelperApp"
  -- Register Growl
  on growlRegister()
    tell application "GrowlHelperApp"
      register as application ¬
        "GrowlHelperApp" all notifications {"Alert"} ¬
        default notifications {"Alert"} ¬
        icon of application "GrowlHelperApp.app"
    end tell
  end growlRegister
  
  -- Notify using Growl 
  on growlNotify(grrTitle, grrDescription)
    tell application "GrowlHelperApp"
      notify with name "Alert" title grrTitle ¬
        description grrDescription ¬
        application name "GrowlHelperApp"
    end tell
  end growlNotify
end using terms from

require 'hotcocoa'
require 'erb'
framework 'webkit'
class Application
  include HotCocoa
  FULL={:expand =&gt; [:width,:height]}
  LINE="They typed &lt;span class='cmd'&gt;&lt;%=cmd%&gt;&lt;/span&gt;"
  BASE=&lt;&lt;-END
  &lt;html&gt;&lt;head&gt;&lt;style type='text/css'&gt;
  * { font-family: Monaco; }
  .cmd { color:red; }
  &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h3&gt;Hello ERB&lt;/h3&gt;&lt;/body&gt;&lt;/html&gt;
  END
  def initialize
    @line=Proc.new {|cmd| ERB.new(LINE).result(binding)}
  end
  def document
    @web_view.mainFrame.DOMDocument
  end
  def write(cmd)
    root = document.createElement("div");
    root.innerHTML=@line.call(cmd);
    document.body.appendChild(root)
  end
  #basically onload event (frameLoadDelegate)
  def webView view, didFinishLoadForFrame: frame
    write("first")
    write("second")
  end
  def start
    application :name =&gt; "MyErbTemplate" do |app|
      app.delegate = self
      window :title =&gt; "MyErbTemplate",
        :frame =&gt; [10, 620, 330, 230] do |win|
        win &lt;&lt; @web_view=web_view(:layout =&gt; FULL) do |wv|
          wv.mainFrame.loadHTMLString BASE, baseURL: nil
          wv.frameLoadDelegate=self
        end
        win.will_close { exit }
      end
    end
  end
end
Application.new.start

require 'hotcocoa'
require 'erb'
framework 'webkit'
class Application
  include HotCocoa
  FULL={:expand => [:width,:height]}
  LINE="They typed <span class='cmd'><%=cmd%></span>"
  BASE=<<-END
  <html><head><style type='text/css'>
  * { font-family: Monaco; }
  .cmd { color:red; }
  </style></head><body><h3>Hello ERB</h3></body></html>
  END
  def initialize
    @line=Proc.new {|cmd| ERB.new(LINE).result(binding)}
  end
  def document
    @web_view.mainFrame.DOMDocument
  end
  def write(cmd)
    root = document.createElement("div");
    root.innerHTML=@line.call(cmd);
    document.body.appendChild(root)
  end
  #basically onload event (frameLoadDelegate)
  def webView view, didFinishLoadForFrame: frame
    write("first")
    write("second")
  end
  def start
    application :name => "MyErbTemplate" do |app|
      app.delegate = self
      window :title => "MyErbTemplate",
        :frame => [10, 620, 330, 230] do |win|
        win << @web_view=web_view(:layout => FULL) do |wv|
          wv.mainFrame.loadHTMLString BASE, baseURL: nil
          wv.frameLoadDelegate=self
        end
        win.will_close { exit }
      end
    end
  end
end
Application.new.start

require 'hotcocoa'
framework 'webkit'
class Application
  include HotCocoa
  FULL={:expand =&gt; [:width,:height]}
  def start
    application :name =&gt; "Myapp" do |app|
      app.delegate = self
      window :title =&gt; "Myapp",
        :frame =&gt; [10, 520, 330, 330] do |win|
        win &lt;&lt; split_view(:horizontal =&gt; true,
          :layout =&gt; FULL) do |sv|
          sv &lt;&lt; web_view(:url =&gt;nil,
             :frame =&gt; [0,0,0,200], :layout =&gt; FULL)
          sv &lt;&lt; @prompt = text_field(:text =&gt; 'type here',
             :frame =&gt; [0,0,0,100], :layout =&gt; FULL, 
             :font =&gt; font(:name=&gt;'Monaco', :size =&gt; 16))
        end
        win.contentView.margin = 5
        win.makeFirstResponder @prompt
        win.will_close { exit }
      end
    end
  end
end
a=Application.new.start

require 'hotcocoa'
framework 'webkit'
class Application
  include HotCocoa
  FULL={:expand => [:width,:height]}
  def start
    application :name => "Myapp" do |app|
      app.delegate = self
      window :title => "Myapp",
        :frame => [10, 520, 330, 330] do |win|
        win << split_view(:horizontal => true,
          :layout => FULL) do |sv|
          sv << web_view(:url =>nil,
             :frame => [0,0,0,200], :layout => FULL)
          sv << @prompt = text_field(:text => 'type here',
             :frame => [0,0,0,100], :layout => FULL, 
             :font => font(:name=>'Monaco', :size => 16))
        end
        win.contentView.margin = 5
        win.makeFirstResponder @prompt
        win.will_close { exit }
      end
    end
  end
end
a=Application.new.start

require 'hotcocoa'
framework 'webkit'
class Application
  include HotCocoa
  FULL={:expand =&gt; [:width,:height]}
  def local_page_url
    bundle=NSBundle.mainBundle
    raise "no mainBundle" unless bundle
    path=NSBundle.pathForResource("index",
        :ofType =&gt; "html",
        :inDirectory =&gt; bundle.bundlePath)
    raise "no Contents/Resources/index.html" unless path
    "file://#{path}"
  end
  def start
    application :name =&gt; "Myapp" do |app|
      app.delegate = self
      window :title =&gt; "Myapp",
        :frame =&gt; [10, 620, 330, 230] do |win|
          win &lt;&lt; web_view(:url =&gt;local_page_url,
            :layout =&gt; FULL)
        win.contentView.margin = 5
        win.will_close { exit }
      end
    end
  end
end
Application.new.start

require 'hotcocoa'
framework 'webkit'
class Application
  include HotCocoa
  FULL={:expand => [:width,:height]}
  def local_page_url
    bundle=NSBundle.mainBundle
    raise "no mainBundle" unless bundle
    path=NSBundle.pathForResource("index",
        :ofType => "html",
        :inDirectory => bundle.bundlePath)
    raise "no Contents/Resources/index.html" unless path
    "file://#{path}"
  end
  def start
    application :name => "Myapp" do |app|
      app.delegate = self
      window :title => "Myapp",
        :frame => [10, 620, 330, 230] do |win|
          win << web_view(:url =>local_page_url,
            :layout => FULL)
        win.contentView.margin = 5
        win.will_close { exit }
      end
    end
  end
end
Application.new.start

require 'hotcocoa'
framework 'webkit'
class Application
  include HotCocoa
  def start
    application :name =&gt; "Myapp" do |app|
      app.delegate = self
      window :frame =&gt; [100, 100, 600, 400],
             :title =&gt; "Myapp" do |win|
        win &lt;&lt; web_view(:frame =&gt; [0,0,200,300],
             :layout =&gt; {:expand =&gt; [:width, :height]}
             ) do |wv|
          wv.url='http://google.com/'
        end
        win.contentView.margin = 5
        win.will_close { exit }
      end
    end
  end
end
Application.new.start

require 'hotcocoa'
framework 'webkit'
class Application
  include HotCocoa
  def start
    application :name => "Myapp" do |app|
      app.delegate = self
      window :frame => [100, 100, 600, 400],
             :title => "Myapp" do |win|
        win << web_view(:frame => [0,0,200,300],
             :layout => {:expand => [:width, :height]}
             ) do |wv|
          wv.url='http://google.com/'
        end
        win.contentView.margin = 5
        win.will_close { exit }
      end
    end
  end
end
Application.new.start