Skip to content

Instantly share code, notes, and snippets.

@youpy
Created April 25, 2012 07:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save youpy/2487603 to your computer and use it in GitHub Desktop.
Save youpy/2487603 to your computer and use it in GitHub Desktop.
#!/usr/bin/env macruby
framework 'AppKit'
require 'tempfile'
require 'shellwords'
class WindowController < NSWindowController
def awakeFromNib
@timer = NSTimer.scheduledTimerWithTimeInterval(0.1, target:self, selector:'onTimer', userInfo:nil, repeats:true)
end
def applicationShouldTerminateAfterLastWindowClosed(app)
true
end
def onTimer
window = NSApp.windows[0]
return unless window
window.setLevel(NSStatusWindowLevel)
views = window.contentView.subviews
views.each do |view|
if view.respond_to?(:startAnimation)
view.startAnimation(self)
end
if view.class.to_s =~ /slider/i
view.setDoubleValue(rand(100))
end
if view.respond_to?(:setState)
view.setState(rand > 0.5 ? NSOnState : NSOffState)
end
if view.respond_to?(:highlight)
view.highlight(rand > 0.9)
end
if view.respond_to?(:setBezelStyle)
view.setBezelStyle(rand(15) + 1)
end
end
end
end
# path for .xib
xib_path = ARGV.shift
# create .nib
tmpfile = Tempfile.new('tmp.nib')
system("ibtool #{Shellwords.escape(xib_path)} --compile #{Shellwords.escape(tmpfile.path)}")
nib = NSNib.alloc.initWithContentsOfURL(NSURL.fileURLWithPath(tmpfile.path))
owner = WindowController.new
app = NSApplication.sharedApplication
app.setDelegate(owner)
nib.instantiateNibWithOwner(owner, topLevelObjects:nil)
NSApp.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment