16

The app TouchSwitcher add item beside lightscreen and volume items : https://hazeover.com/touchswitcher.html enter image description here

Is there a solution to display an item into the control strip on the right region of touch bar ?

I can't find any help in official documentation about it... Please help me !

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
MattOZ
  • 313
  • 3
  • 7
  • From the NSTouchBar documentation: "On the right side of the Touch Bar, the system supplies the always-available Control Strip. The Control Strip gives the user access to standard controls for display brightness, sound volume, Siri, and so on. Your app’s bars appear to the left of the Control Strip. (The user can choose to hide the Control Strip, which gives the frontmost app the entire Touch Bar width.)" This implies that your app's bars always appear to the left and items to the right aren't possible. You can't even access the Control Strip bar items. – rocky Dec 01 '16 at 22:10

2 Answers2

5

After decompiling, I discovered some APIs in a framework called DFRFoundation located under /System/Library/PrivateFrameworks, and a related method DFRElementSetControlStripPresenceForIdentifier. I find it quite difficult to get further, so I answer here only to let you know that the API for this is in a private framework. Hope someone would reveal the secrets someday.

yxonic
  • 51
  • 4
5

Here's what I use. Pass an NSView and an identifier of your choice to the controlStrippify() function. My attempts at doing the exact same thing using Swift have resulted in crashes, ports welcome :). Inspiration from https://github.com/a2/touch-baer.

@import Cocoa;
@import Foundation;

// See: https://github.com/a2/touch-baer
extern void DFRElementSetControlStripPresenceForIdentifier(NSString *string, BOOL enabled);

@interface NSTouchBarItem ()
+ (void)addSystemTrayItem:(NSTouchBarItem *)item;
@end

@interface NSTouchBar ()
+ (void)presentSystemModalFunctionBar:(NSTouchBar *)touchBar systemTrayItemIdentifier:(NSString *)identifier;
@end

void controlStrippify(NSView *view, NSString *identifier) {
  if (@available(macOS 10.12.2, *)) {
    NSCustomTouchBarItem *touchBarItem = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier];
    touchBarItem.view = view;
    [NSTouchBarItem addSystemTrayItem:touchBarItem];
    DFRElementSetControlStripPresenceForIdentifier(identifier, YES);
  } else {
    // Fail!
  }
}
Johan Walles
  • 1,447
  • 2
  • 15
  • 23