Created
February 12, 2011 10:55
-
-
Save quackingduck/823693 to your computer and use it in GitHub Desktop.
A one-file MacRuby app
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' | |
# Inspired by: http://cocoawithlove.com/2010/09/minimalist-cocoa-programming.html | |
# Inits NSApp | |
NSApplication.sharedApplication | |
# Allows an app without an applicaiton bundle or info.plist to still be an app | |
NSApp.setActivationPolicy NSApplicationActivationPolicyRegular | |
# The menu bar iteself | |
NSApp.setMainMenu(NSMenu.new.tap do |menu| | |
# The first item on the left of the menu bar | |
menu.addItem(NSMenuItem.new.tap do |menu_item| | |
# The submenu of the first item | |
menu_item.setSubmenu(NSMenu.new.tap do |sub_menu| | |
# The only item in the submenu: Quit | |
sub_menu.addItem NSMenuItem.alloc. | |
initWithTitle "Quit #{NSProcessInfo.processInfo.processName}", | |
action: 'terminate:', | |
keyEquivalent: 'q' | |
end) | |
end) | |
end) | |
# Create window with dimensions: x,y,w,h | |
NSWindow.alloc.initWithContentRect( | |
[200,300,300,100], | |
styleMask:NSTitledWindowMask, | |
backing: NSBackingStoreBuffered, | |
defer: false | |
).tap do |win| | |
# Minimal window config | |
win.title = "imma window, imma imma window" | |
win.orderFrontRegardless | |
end | |
# Loads this app in front of the terminal (or whatever launched it) | |
NSApp.activateIgnoringOtherApps true | |
# Start the run loop | |
NSApp.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment