开发者

NSApplicationDelegate prevent window if command line present

I have a simple single wi开发者_如何学Pythonndow app, with a drop target on it for files. This works fine. However, I also want that when it is started with a command line, it just processes those files instead, rather than showing a window.

Is there a delegate method in NSApplicationDelegate that I can prevent the window from showing, process the files and quit the application in?


You can set the window not to show when loaded from the nib file. There's a setting in the inspector in the Interface builder.

Then you can show the window if necessary, using methods described in this documentation.

But this will still show the icon in the Dock while your app is processing the file.


You can prevent showing the main window like Yuji said. There's also a notification called applicationDidFinishLaunching: There you can process your files and quit the application with [[NSApplication sharedApplication] terminate:self];


The most maintainable and simple approach I've seen to this is to put your commandline version in a separate executable as a simple Foundation program, and then make your Cocoa program just call it, handling the UI. Doing it this way gets rid of many of the things you'd need to work around. You can then install links to your commandline version where you like.

If you dislike using NSTask for this, then put your logic into a shared framework, and layer GUI and commandline apps on top of it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜