Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent iCloud open file dialog from appearing on startup in OS X [duplicate]

When you open an iCloud enabled document based app on Mac without any currently open documents the open file dialog will appear. How do you prevent that open file dialog from appearing on startup? I have a welcome screen I prefer to show instead.

like image 388
Berry Blue Avatar asked Dec 06 '15 02:12

Berry Blue


1 Answers

To verify your statement I created a fresh document based application project in XCode and ran it. I don't get an open file dialog! I do get a blank new document opened though. Is that what you meant? I could not find any documented way of suppressing this initial blank document being opened. I managed to suppress this behavior with the following hack, using the initializer of your Document class:

- (instancetype)init {
    self = [super init];
    if (self) {
        // Add your subclass-specific initialization here.
    }
    NSLog(@"Document init");
    if (alreadysuppressed)
        return self;
    alreadysuppressed = 1;
    return nil;
}

As you can see, it makes use of a variable (called 'alreadysuppressed' here) to remember if the suppression was already done, so it will be done once per application run. I know it's a hack but it works for the generic document based application. If you are really getting the file open dialog instead of the above behavior then I suggest adding a similar hack to your application delegate class:

- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender
{
    NSLog(@"applicationShouldOpenUntitledFile: %d", alreadysuppressed);
    if (! alreadysuppressed) {
        alreadysuppressed = 1;
        return NO;
    }
    return YES;
}

Though I could not test this scenario as I am not getting the file open dialog in the generic document based application.

like image 108
Rudi Angela Avatar answered Sep 18 '22 07:09

Rudi Angela