Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide the initial window on start with OS X storyboards

I am creating an OS X status bar application, so I want the application to start hidden.

I have created a "storyboard" application, and the initial window always shows up, even if "Visible at launch" is unchecked (was unchecked by default).


Note: if I disable "Is initial controller" then the app correctly starts without any window, but my (now orphan) window seems to never be added to the storyboard:

var mainWindow = NSStoryboard(name: "Main", bundle: nil)?.instantiateControllerWithIdentifier("mainWindow")

The "mainWindow" controller is not found (even though I correctly set "Storyboard ID" on the Window Controller).

So I think it's better to leave "Is initial controller" but simply have the main window hidden at the start…

like image 865
Matthieu Napoli Avatar asked Jan 17 '15 11:01

Matthieu Napoli


People also ask

How do I hide a window in OSX?

Command-H: Hide the windows of the front app. To view the front app but hide all other apps, press Option-Command-H. Command-M: Minimize the front window to the Dock. To minimize all windows of the front app, press Option-Command-M.

How do you float a window at the top of a Mac?

Updated at 07 Feb, 2022 07:25 PM. If you want Tot's window to float above other windows on the Mac desktop, use the "Display as Floating Window" item in the Window menu. Note that the Window menu is only visible when you're using Tot with a Dock icon.

How do I keep the top window on safari?

Open the window you want it to be on top. Then, click CTRL + SPACE. Then, you will see that the window will stay on top no matter which app you open later. 10.


2 Answers

Uncheck "Is Initial Controller", but then you need to set the storyboard and its associated NSWindowController manually.

The precise way of doing that is shown in this answer, which I'll quote here:

[...] in your AppDelegate, set up a property for the window controller:

@property NSWindowController *myController;

In your applicationDidFinishLaunching: method implementation, create a reference to the Storyboard. This way you get access your window controller from the storyboard. After that, the only thing left to do is to display the window by sending your window controller the showWindow: method.

#import "AppDelegate.h"

@interface AppDelegate ()
@end

@implementation AppDelegate

@synthesize myController;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    // get a reference to the storyboard
    NSStoryboard *storyBoard = [NSStoryboard storyboardWithName:@"Main" bundle:nil]; 
    // instantiate your window controller 
    myController = [storyBoard instantiateControllerWithIdentifier:@"secondWindowController"];
    // show the window
    [myController showWindow:self];
}

@end
like image 179
adfernandes Avatar answered Oct 04 '22 15:10

adfernandes


Uncheck the "Is Initial Controller" box on the storyboard, leaving your app without an initial controller. Your app will run, but will have no window.

screenshot

like image 30
Tim Shadel Avatar answered Oct 04 '22 15:10

Tim Shadel