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?
4 Answers
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.
Depends of your Application functionality you may subclass NSDocumentController and return empty array for documentClassNames property.
class MyDocumentController: NSDocumentController {
override var documentClassNames: [String] {
return [] // This will disable "+" plus button in NSWindow tab bar.
}
}
Here is a documentation of the documentClassNames property:
documentClassNames
An array of strings representing the custom document classes supported by this app.The items in the array are
NSString
objects, each of which represents the name of a document subclasses supported by the app. The document class names are derived from the app’sInfo.plist
. You can override this property and use it to return the names of document classes that are dynamically loaded from plugins.
And here is explanation how documentClassNames property affects NSWindow tab bar plus button appearance:
New Button
The plus button will be shown if
newWindowForTab:
is implemented in the responder chain.NSDocumentController
informally implementsnewWindowForTab:
, but only returns YES fromrespondsToSelector:
for this selector if theself.documentClassNames.count > 0
and if the app has a default new document type. In other words, it only responds to it ifNSDocument
has at least one registered document class name which can be edited.

- 6,402
- 1
- 60
- 74

- 5,981
- 3
- 21
- 24
-
4It disables all the window tabbing feature. Not only the add new button... – 1024jp Oct 25 '16 at 17:29
Change this
@IBAction override func newWindowForTab(_ sender: Any?) {}
into this
@IBAction func myButton(_ sender: Any?) {}
This will hide the plus button. The tabbing still works
-
That makes no sense. Where would the first declaration even exist, so that I can change it? – Thomas Tempelmann Jan 22 '21 at 19:35