From: Dave H. <gr...@gr...> - 2005-06-06 21:22:01
|
On Jun 6, 2005, at 12:47 AM, Jonathan Paisley wrote: > Look at the documentation for [NSApplication sharedApplication] - this > is the method you use to get a reference to the single NSApplication > object. This happens to be stored in the global variable NSApp too for > convenience, but I don't think it's accessible from Ruby. > > So, you'd do: > > app = OSX::NSApplication.sharedApplication the rb_main.rb file contains if $0 == __FILE__ then rb_main_init OSX.NSApplicationMain(0, nil) end if it instead had if $0 == __FILE__ then rb_main_init app = OSX.NSApplicationMain(0, nil) end would that work? I tried that, but it appears that "app" was too local, and vanished before I could access it. But it's quite possible I just don't have a good enough grasp of variable scope to have figured out how to set that up correctly. > Having said this, I think it's rare that you actually need a reference > to the application itself - what do you need it for? I'm trying to get my hands on the window list, in this particular case, although I've certainly used the "hidden," "name," and "active" properties in the past. I spent a lot of time scouring the Apple documentation trying to find a way to get an app's list of windows, rereading the documentation for NSWindow, NSApplication, and NSWindowController as well as the "how to use windows" section, and found no hint of any alternative to the application's "windows" method. OTOH, I guess I need to serve myself up a slice of humble pie, since I did say "I don't think a Cocoa manual's going to be much help there," but it turns out that a single sentence in the NSApplication documentation did actually have the answer... "sharedApplication only performs the initialization once; if you invoke it more than once, it simply returns the NSApplication object it created previously." Hmmm. |