Skip to content

@youpy /animate_xib.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
#!/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
Something went wrong with that request. Please try again.