Created
June 14, 2018 15:33
-
-
Save thundernixon/3d615e44ece28a41138aa35014ad2cfb to your computer and use it in GitHub Desktop.
RoboFont miniscript: Close all open fonts, unless they have unsaved changes. Leave code & other windows open.
This file contains 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
#################################################################### | |
###### Close all open fonts, unless they have unsaved changes ###### | |
#################################################################### | |
###### Doesn't affect the windows of extensions, code, etc :) ###### | |
#################################################################### | |
###### Hook it up to a keyboard shortcut for quick & easy use ###### | |
#################################################################### | |
from mojo.UI import dontShowAgainMessage | |
unsavedFonts = [] | |
for font in AllFonts(): | |
fontName = font.info.familyName + " " + font.info.styleName | |
document = font.document() | |
edited = None | |
if document: | |
# only font objects with ui has a document object | |
edited = document.isDocumentEdited() | |
# if a font has unsaved changes, add them to the list | |
if edited: | |
unsavedFonts.append(fontName) | |
# close fonts if they have no unsaved changes | |
else: | |
font.close() | |
unsavedFontList = "" | |
# make a string which is a bulleted list of unsaved fonts | |
for item in unsavedFonts: | |
if len(unsavedFonts) > 1: | |
unsavedFontList += " → " + item + "\n" | |
else: | |
unsavedFontList = item | |
# give some context to the user | |
roboGreeting = "closeAllFonts.py says:\n\n" | |
# make the message to handle multiple or single fonts | |
if len(unsavedFonts) > 1: | |
unsavedMessage = roboGreeting + "There are unsaved changes in the following fonts:\n" + unsavedFontList + "\n Please close them manually.\n" | |
else: | |
unsavedMessage = roboGreeting + "There are unsaved changes in " + unsavedFontList + ". Please close it manually.\n" | |
# alert user | |
if len(unsavedFonts) > 0: | |
dontShowAgainMessage(messageText='🤖 Unsaved changes 🤖', informativeText=unsavedMessage, alertStyle=1, parentWindow=None, resultCallback=None, dontShowAgainKey='') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment