Search code examples
cocoatabsnswindownsdocumentmacos-sierra

Hide NSWindow New tab button


In macOS 10.12 there is a new tab bar that is added to NSWindows for NSDocument apps. You can prevent the toolbar from appearing (see How do I disable the Show Tab Bar menu option in Sierra apps?). But how to remove the "+" button for adding new Windows?


Solution

  • According to the AppKit release notes, returning false for responding newWindowForTab(_:) action message in a NSDocumentController subclass disables "+" button in the tab bar.

    override func responds(to aSelector: Selector!) -> Bool {
    
        if #available(OSX 10.12, *) {
            if aSelector == #selector(NSResponder.newWindowForTab(_:)) {
                return false
            }
        }
    
        return super.responds(to: aSelector)
    }
    

    See "New Button" section in the AppKit Release Notes for macOS 10.12.