Glyphs.boolDefault returns wrong values

Hi,

I’m on Glyphs 3.0.5 (3117), and I’m getting an unexpected result when calling Glyphs.boolDefaults.

When the default I am calling for is “truthy”, boolDefaults returns False.

boolDefaults only returns True if the default is literally True, not just “truthy” as is expected.

Try the code below in the macro window.

Glyphs.clearLog()
# Should be False if it doesn't exist/returns None
assert Glyphs.boolDefaults["com.foo.bar"] == False # Passes

# Should be True if it is set/is Truthy
Glyphs.defaults["com.foo.bar"] = "baz"
assert bool(Glyphs.defaults["com.foo.bar"]) == True # Passes
assert Glyphs.boolDefaults["com.foo.bar"] == True # Fails

# Only returns True if value is literally "True"
Glyphs.defaults["com.foo.bar"] = True
assert Glyphs.boolDefaults["com.foo.bar"] == True # Passes

Returns:

Traceback (most recent call last):
  File "<macro panel>", line 8
AssertionError

As I understand it from the Python API documentation, it should return True on anything that is “truthy”:
https://docu.glyphsapp.com/#GSApplication.boolDefaults

Glyphs.boolDefaults returns True whatever Cocoa thinks is true, not what python considers so. It calls NSUserDefaults.standardUserDefaults().boolForKey_(key) and returns that as is. It could do bool(NSUserDefaults.standardUserDefaults().objectForKey_(key)). Not sure what is better. For me, looking from the ObjectiveC side, the first makes more sense :wink:

(you know that you can get to the details on how things are implemented here: github.com/schriftgestalt/GlyphsSDK/blob/Glyphs3/ObjectWrapper/GlyphsApp/init.py ?)

Thanks! And thanks for the link, I will use it in the future.

Maybe it should be more explicit in the documentation, though :slight_smile: Since it’s the Python API, I assumed it would use Python rules for what is True.