objc
objc copied to clipboard
How to get NSView or NSWindow?
I want to get current NSView or NSWindow. Is it possible?
Not sure what you mean, tbh. It seems to me like that's something that would fall into the scope of AppKit, rather than this library.
I want to get current NSView or NSWindow. Is it possible?
Have you reslove this problem? Do you know the method , thanks
This is essentially how you'd do it:
// Import AppKit to get access to its symbols (like NSApplication)
const objc = require('objc');
objc.import('AppKit');
// Once the application has started, and a window is available, you
// can get a reference to it like this:
const mainWindow = objc.NSApplication.sharedApplication().mainWindow();
For an example of starting up an application from scratch, see https://github.com/lukaskollmer/objc/pull/43 (where I actually initialise the NSWindow myself, so getting a reference to it is easy).
If you want to control an already-running app using this (which it seems many Electron users do), I have no idea whether that's even possible (if nothing else due to macOS sandboxing apps from each other). It would be easiest to start up and manage the entire app using this framework rather than attach to an existing one.