The app TouchSwitcher add item beside lightscreen and volume items : https://hazeover.com/touchswitcher.html
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 !
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 DFRSystemModalShowsCloseBoxWhenFrontMost(BOOL);
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, *)) {
DFRSystemModalShowsCloseBoxWhenFrontMost(YES);
NSCustomTouchBarItem *touchBarItem = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier];
touchBarItem.view = view;
[NSTouchBarItem addSystemTrayItem:touchBarItem];
DFRElementSetControlStripPresenceForIdentifier(identifier, YES);
} else {
// Fail!
}
}
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.
来源:https://stackoverflow.com/questions/40920204/how-get-an-item-in-control-center-of-touch-bar-on-the-right