Skip to content

Instantly share code, notes, and snippets.

@connordavenport
Last active September 28, 2023 20:15
Show Gist options
  • Select an option

  • Save connordavenport/5c242deba24153b8cc8bd80a52e081f2 to your computer and use it in GitHub Desktop.

Select an option

Save connordavenport/5c242deba24153b8cc8bd80a52e081f2 to your computer and use it in GitHub Desktop.
A startup script for RoboFont that will automatically group/tabulate your fonts by info.familyName
from mojo.subscriber import Subscriber, registerRoboFontSubscriber
import AppKit
class MargielaTabs(Subscriber):
def fontDocumentDidOpen(self,info):
newFont = info["lowLevelEvents"][0]["font"]
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(newFont.info.familyName)
if windows and len(windows) > 1:
'''
we cant select the first one because that is the
newest font and it would move the other font windows.
'''
main = next((window for window in windows if window.document().font.path != newFont.path), -1)
if main in windows: windows.remove(main)
for window in windows:
if window.document().font.path == newFont.path:
main.addTabbedWindow_ordered_(window, AppKit.NSWindowAbove)
registerRoboFontSubscriber(MargielaTabs)
@colinmford
Copy link
Copy Markdown

@connordavenport changing line 11 to the following makes it work for Single Window Mode as well:

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]

@connordavenport
Copy link
Copy Markdown
Author

Ahh yes yes, good point! Thanks, @colinmford!

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