Created
April 25, 2012 07:00
-
-
Save youpy/2487603 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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