How do I disable the Show Tab Bar menu option in Sierra apps?
Asked Answered
R

6

20

I've got an app that uses a Toolbar in a NSWindow. I don't want users to be able to customize this toolbar for aesthetic reasons. In Sierra there's a new Menu option that gets inserted into "Menu > View" called Show Tab Bar. How do I disable this? Enabling it only seems to increase the tool bar's height as I don't have extra labels showing under the icons.

Rennes answered 8/9, 2016 at 20:21 Comment(0)
R
18

On 10.12, you need to now set the following when the window is created as Tab Bar is now available by default:

[NSWindow setAllowsAutomaticWindowTabbing: NO];

The answer is the same in Swift and SwiftUI

func applicationWillFinishLaunching(_ notification: Notification) {
    NSWindow.allowsAutomaticWindowTabbing = false
}

Note that the call is made on the class NSWindow not on an instance of NSWindow

Rennes answered 11/9, 2016 at 17:14 Comment(2)
On 10.15 this method no longer seems to exist. Instead you can set the tabbingMode of the window to .disallowed. Specifically adding window.tabbingMode = .disallowed to the applicationDidFinishLaunching method of the NSApplicationDelegate seems to work.Seamy
The above comment is not true, it seems like they may have been trying to call allowsAutomaticWindowTabbing on an instance of a window rather than on NSWindow the class. In swift and swiftui you can still call NSWindow.allowsAutomaticWindowTabbing = false to remove these items entirely in all app windows rather than disabling them for individual windows.Topside
K
33

You can also do this on IB, on the Window’s attributes inspector

NSWindow attribute inspector

Kimmie answered 30/9, 2016 at 8:17 Comment(3)
Thanks a lot. This helped me.Dodgem
where exactly this screen is located at?Oneil
You can also do it programmatically using the following code window.tabbingMode = NSWindowTabbingModeDisallowedFescennine
R
18

On 10.12, you need to now set the following when the window is created as Tab Bar is now available by default:

[NSWindow setAllowsAutomaticWindowTabbing: NO];

The answer is the same in Swift and SwiftUI

func applicationWillFinishLaunching(_ notification: Notification) {
    NSWindow.allowsAutomaticWindowTabbing = false
}

Note that the call is made on the class NSWindow not on an instance of NSWindow

Rennes answered 11/9, 2016 at 17:14 Comment(2)
On 10.15 this method no longer seems to exist. Instead you can set the tabbingMode of the window to .disallowed. Specifically adding window.tabbingMode = .disallowed to the applicationDidFinishLaunching method of the NSApplicationDelegate seems to work.Seamy
The above comment is not true, it seems like they may have been trying to call allowsAutomaticWindowTabbing on an instance of a window rather than on NSWindow the class. In swift and swiftui you can still call NSWindow.allowsAutomaticWindowTabbing = false to remove these items entirely in all app windows rather than disabling them for individual windows.Topside
C
5

To disable tabbing on individual windows call setTabbingMode:

if([window respondsToSelector:@selector(setTabbingMode:)]) {
    // this particular window doesn't support tabbing in Sierra.
    [window setTabbingMode:NSWindowTabbingModeDisallowed];
}
Comfy answered 27/11, 2016 at 7:35 Comment(0)
S
4

If you don't want to compile against the latest frameworks, you can use the following code in your NSWindowsController sub classes:

Swift:

 override func awakeFromNib() {
     if NSAppKitVersionNumber > 1500 {
        self.window?.setValue(2, forKey: "tabbingMode")
     }
 }

Objective-C:

- (void)awakeFromNib {
    if (NSAppKitVersionNumber > 1500) {
        [self.window setValue:[NSNumber numberWithInt:2] forKey:@"tabbingMode"];
    }
}
Suboxide answered 21/9, 2016 at 8:9 Comment(2)
It's NSAppKitVersion.current.rawValue > NSAppKitVersion.macOS10_12.rawValue with Swift 4Roslynrosmarin
@ctietze: my answer os only relevant when using older versions of Xcode and SwiftSuboxide
N
4

Swift solution:

override func awakeFromNib() {
    super.awakeFromNib()
    if #available(OSX 10.12, *) {
        tabbingMode = .disallowed
    }
}
Nilson answered 22/12, 2016 at 14:13 Comment(1)
Or, if you have an app delegate, add the line window.tabbingMode = .disallowed after the NSWindow has been created.Seamy
K
4

Swift 5

In your NSWindowController:

self.window?.tabbingMode = .disallowed
Kendy answered 7/4, 2020 at 18:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.