UNSOLVED Observe “Update Menu”



  • Hi there,

    Is there some way I can set up an observer to fire when the Scripts menu is refreshed? (Caused by either clicking Scripts > Update Menu, or when it is refreshed on its own via some other RF function?)

    Thanks!



  • @frederik Thanks!!


  • admin

    I see

    will add such a notification: scriptsMenuChanged



  • Hey @frederik,

    It's admittedly a little hacky, but I like to keep a version number on our internal library so I can tell at a glance what version RF has loaded:

    d3eb1d21-9b91-4512-8533-4ea398267165-image.png

    I do this with a script similar to this:

    from AppKit import NSApp, NSMenu, NSMenuItem
    from mojo.events import addObserver, removeObserver
    
    from hco import __version__
    
    class ShowVersionInfo:
        def __init__(self):
            addObserver(self, "waitForActive", "applicationDidFinishLaunching")
    
        def waitForActive(self, sender):
            # This is a hack to get it to wait until the application is _really_ ready
            addObserver(self, "addInfo", "applicationDidBecomeActive")
    
        def addInfo(self, sender):
            removeObserver(self, "applicationDidFinishLaunching")
            removeObserver(self, "applicationDidBecomeActive")
    
            menubar = NSApp().mainMenu()
    
            scripts = menubar.itemWithTitle_("Scripts").submenu()
            hco = scripts.itemWithTitle_("H&Co").submenu()
    
            info = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Internal Design Tools v"+__version__, '', '')
            hco.insertItem_atIndex_(NSMenuItem.separatorItem(), 0)
            hco.insertItem_atIndex_(info, 0)
    
    ShowVersionInfo()
    

    When the script menu is updated through "Update Menu" or some other internal function, the version string and divider bar are removed — it's annoying that it's not there anymore, but not a big issue.

    If there is some observer that fires after a menu refresh was run, I could re-add that version info.


  • admin

    why would you need such an observer?