-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathExport-and-install.py
28 lines (26 loc) · 973 Bytes
/
Export-and-install.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#MenuTitle: Export and install font
# -*- coding: utf-8 -*-
__doc__="""
Exports and installs all active instances of this font and avoids caching.
"""
import os
import re
import datetime
installFolder = os.path.expanduser("~/Library/Fonts")
suffix = datetime.datetime.now().strftime("%Y%m%d-%H%M")
font = Glyphs.font
for instance in font.instances:
try:
if instance.active:
filePattern = r"^%s(-[\d-]+)?\.(otf|ttf)" % instance.fontName
oldFonts = [f for f in os.listdir(installFolder) if re.match(filePattern, f)]
for oldFont in oldFonts:
os.remove(installFolder + "/" + oldFont)
print "Uninstalled %s" % oldFont
fileName = "%s-%s.otf" % (instance.fontName, suffix)
print "Exporting %s" % fileName
instance.generate(FontPath = installFolder + "/" + fileName)
except Exception, e:
print e
print "Exported and installed %s" % font.familyName
Glyphs.showNotification("Export and install fonts", "Exported and installed %s" % font.familyName)