GetFolder() method not working

I’m writing a script that exports all created instances of all currently open files to a chosen location. My idea is to present a modal dialogue to the user by calling GetFolder() and set the returned value as a parameter to the instance.generate() method. Here is the source code (also on Github):

folderPath = GetFolder(message=None, allowsMultipleSelection = False)

for font in Glyphs.fonts:
    for instance in font.instances:
        instance.generate(FontPath = folderPath)

Glyphs.showNotification('Export All Instances', 'Export successful.')

Running the script generates the following error message in the macro panel:

Traceback (most recent call last):
    File "exportAllInstances.py", line 8, in <module>
        folderPath = GetFolder(message=None, allowsMultipleSelection = False)
    File "/Applications/Glyphs.app/Contents/Scripts/GlyphsApp.py", line 2787, in GetFolder
        Panel = NSOpenPanel.openPanel().retain()
objc.error: NSInternalInconsistencyException - not running on AppKit (main) thread

My hunch was this is some dependency issue as I’m on Glyphs 1.4.4, but I was told Glyphs 2.3 generates the very same error. Is this due to a misuse of the method on my part, or is GetFolder() simply not implemented? How can I make it work?

Glyphs 1.4 did run the scripts on a background thread and the error message says that you can’t run UI from there. This is fixed in Glyphs 2. There are some ways to run code on the main thread. Something like this:

def method_that_has_all_the_code(): 
    folderPath = GetFolder(message=None, allowsMultipleSelection = False)
    for font in Glyphs.fonts:
        for instance in font.instances:
            instance.generate(FontPath = folderPath)

from PyObjCTools.AppHelper import callAfter
callAfter(method_that_has_all_the_code, None)

For me this code dismisses the error, but produces no actions or results (I’m on OS X Mavericks).