Skip to content

Instantly share code, notes, and snippets.

@connordavenport
Created August 15, 2025 15:53
Show Gist options
  • Save connordavenport/4d6a3f56c6af89a34555082bb9d8e70c to your computer and use it in GitHub Desktop.
Save connordavenport/4d6a3f56c6af89a34555082bb9d8e70c to your computer and use it in GitHub Desktop.
rename all tabs + unsaved fonts with valid attrs
from mojo.subscriber import Subscriber, registerRoboFontSubscriber, registerCurrentFontSubscriber, unregisterRoboFontSubscriber, unregisterCurrentFontSubscriber
import AppKit
class BASE:
def update_tabs(self, font):
if font:
has_values = True
for val in "familyName styleName".split(" "):
if not hasattr(font.info, val):
has_values = False
if has_values:
windows = [w for w in AppKit.NSApp().orderedWindows() if hasattr(w, "windowName") and "FontWindow" in w.windowName() if RFont(w.document().font) == font]
for w in windows:
doc_font = w.document().font
w.setTitle_(f"{doc_font.info.familyName} {doc_font.info.styleName}")
class Unnamed_Open(Subscriber, BASE):
def fontDocumentDidOpenNew(self,info):
new_font = info["lowLevelEvents"][0]["font"]
self.update_tabs(new_font)
registerRoboFontSubscriber(Unnamed_Open)
class Unnamed_Changed(Subscriber, BASE):
def currentFontInfoDidChangeValue(self, info):
changed_font = info["font"]
iters = info.get("iterations")
if iters:
if iters[0].get("attribute") in "familyName styleName".split(" "):
self.update_tabs(changed_font)
registerCurrentFontSubscriber(Unnamed_Changed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment