Created
May 11, 2022 15:03
-
-
Save connordavenport/a4f31f3b94b2fb3a969b18ecbcfef846 to your computer and use it in GitHub Desktop.
A series of scripts that add "open last font" functionality to RoboFont. Set the CanCloser.py as a startup script and CanCloser.py uses command+shift+T to open the last font.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mojo.extensions import getExtensionDefault, setExtensionDefault | |
from mojo.events import addObserver | |
''' | |
Must set this as a start-up script! | |
This observer adds the font path to a list that can be accessed later | |
''' | |
DEFAULTSKEY = "com.connordavenport.CanOpener" | |
class CanCloser: | |
def __init__(self): | |
addObserver(self,"fontWillCloseObserver","fontWillClose") | |
def fontWillCloseObserver(self,info): | |
font = info["font"] | |
fontPaths = getExtensionDefault(DEFAULTSKEY) | |
if font: | |
if fontPaths: | |
fontPaths.insert(0, font.path) | |
# Limit the amount of files in the list to 10 | |
fontPaths = fontPaths[:10] | |
else: | |
fontPaths = [font.path] | |
setExtensionDefault(DEFAULTSKEY, fontPaths) | |
CanCloser() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# menuTitle : Open Last Closed Font | |
# shortCut : command+shift+T | |
''' | |
This script uses the list of font paths to reopen recentely closed fonts. | |
Similiar to opening old tabs in your browser. | |
''' | |
from mojo.extensions import getExtensionDefault, setExtensionDefault | |
import os.path | |
DEFAULTSKEY = "com.connordavenport.CanOpener" | |
class CanOpener: | |
def __init__(self): | |
# Double check that the font path still exists and isnt already open | |
fontPaths = [fp for fp in getExtensionDefault(DEFAULTSKEY) if os.path.isdir(fp)] | |
if fontPaths: | |
firstFont = fontPaths[0] | |
print(f"opening {os.path.basename(firstFont)}...") | |
OpenFont(firstFont, True) | |
if len(fontPaths) == 1: | |
fontPaths = [] | |
else: | |
fontPaths.remove(firstFont) | |
setExtensionDefault(DEFAULTSKEY, fontPaths) | |
CanOpener() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment