SOLVED applicationWillTerminate doesn’t work as predicted?

  • Hi there,

    I was trying to implement auto-opening ufos on start that were active during the previous RF session.

    Here is the code that I'm putting to the startup scripts batch:

    import os
    from mojo.UI import getDefault, setDefault
    from mojo.roboFont import OpenFont, AllFonts
    from import addObserver, removeObserver
        Startup script that opens recently closed Robofont session
    def openRecentSession():
        paths = getDefault('recentSessionPaths')
        if paths is None: return
        for path in paths:
            if os.path.exists(path):
                OpenFont(path, True)
                print('!!!! opened path', path)
    def saveCurrentSession():
        paths = [f.path for f in AllFonts()]
        if len(paths) == 0:
            paths = None
        setDefault('recentSessionPaths', paths)
    class OpenRecentSessionManager(object):
        def __init__(self): 
            print('openRecentSession =', getDefault('openRecentSession'))
            if getDefault('openRecentSession') == 1:
            addObserver(self, 'robofontClosing', 'applicationWillTerminate')
        def robofontClosing(self, info):
            print('robofotn closing, saving current session', AllFonts())

    My issue: I assumed that applicationWillTerminate observer triggers callback whenever the RF app is being closed. It looks like it is not true. It is hard to tell when closing the RF app will trigger my saveCurrentSession callback.

    Maybe I assumption was wrong, and applicationWillTerminate works completely differently? is there a better way to implement auto-opening the last RF session?

    Thanks in advance for your help
    and please, inform me if the question is not clear enough :)

  • admin

  • admin

    Mmm, I guess in this case all open fonts are already closed, so AllFonts() will be an empty list...

    Dont overcomplicate it to much and try to use macOS callbacks... like:

    import AppKit
    controller = AppKit.NSDocumentController.sharedDocumentController()

Log in to reply