Skip to content

Instantly share code, notes, and snippets.

@connordavenport
Created October 21, 2025 13:01
Show Gist options
  • Save connordavenport/429812c42c96763fc468dc41bae1b532 to your computer and use it in GitHub Desktop.
Save connordavenport/429812c42c96763fc468dc41bae1b532 to your computer and use it in GitHub Desktop.
from mojo.subscriber import Subscriber, registerRoboFontSubscriber
import AppKit
class MargielaTabs(Subscriber):
def fontDocumentWantsToolbarItems(self, info):
image = AppKit.NSImage.imageWithSystemSymbolName_accessibilityDescription_("arrow.trianglehead.merge", "")
newItem = {'itemIdentifier': 'MargielaTabsButton',
'label': 'Margiela',
'toolTip': 'Merge Tabs',
'imageObject': image,
'callback': self.compile}
info['itemDescriptions'].insert(5, newItem)
def run(self, loaded_font=None):
merge_all = False
if not loaded_font:
loaded_font = CurrentFont()
if AppKit.NSEvent.modifierFlags() & AppKit.NSShiftKeyMask:
# if shift down, merge all windows regardless of familyName
merge_all = True
windows = [w for w in AppKit.NSApp().orderedWindows() if hasattr(w, "windowName") and "FontWindow" in w.windowName()]
else:
# merge windows by familyName
windowsMap = {}
allFonts = {f.info.familyName:AllFonts().getFontsByFamilyName(f.info.familyName) for f in AllFonts()}
for familyName,fonts in allFonts.items():
windowsMap[familyName] = [w for w in AppKit.NSApp().orderedWindows() if hasattr(w, "windowName") and "FontWindow" in w.windowName() and w.document().font.info.familyName == familyName]
windows = windowsMap.get(loaded_font.info.familyName)
wind_len = len(windows)
if wind_len == 1:
windows[0].setToolbarStyle_(0)
elif wind_len > 1:
'''
we cant select the first one because that is the
newest font and it would move the other font windows.
'''
for __ in windows:
__.setToolbarStyle_(0) # set toolbar style upon opening
run = True
if run:
main = next((window for window in windows if window.document().font.path != loaded_font.path), -1)
if main in windows: windows.remove(main)
for window in windows:
if window.document().font.path == loaded_font.path:
main.addTabbedWindow_ordered_(window, AppKit.NSWindowAbove)
else:
pass
def compile(self, sender):
self.run()
def fontDocumentDidOpen(self,info):
newFont = info["lowLevelEvents"][0]["font"]
self.run(newFont)
registerRoboFontSubscriber(MargielaTabs)
@okay-type
Copy link

This cool. Any idea how to change the focus of the tabs? I tried to make it sync to edit next master but couldn't quite get there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment