Corrupted Variables after Custom HTML SetVariable [Update: I fixed it - please read]

HELP!

I was playing with the keyboard maestro custom HTML prompt and I executed the following javascript:

<input onclick="window.KeyboardMaestro.SetVariable('MyTestVar',this.checked)" name="Web_Checkbox" class="input" type="checkbox" id="checkbox" />

And now I can no longer bring up the keyboard maestro preferences window, nor can I display any variables in my ‘dropdown’ list of variables (for instance for inserting a variable in a text box).

For the record, the console gives me this error:

2/4/16 2:31:03.666 PM Keyboard Maestro[61312]: -[__NSCFBoolean isEqualToString:]: unrecognized selector sent to instance 0x7fff78d8ee50
2/4/16 2:31:03.666 PM Keyboard Maestro[61312]: An uncaught exception was raised
2/4/16 2:31:03.666 PM Keyboard Maestro[61312]: -[__NSCFBoolean isEqualToString:]: unrecognized selector sent to instance 0x7fff78d8ee50
2/4/16 2:31:03.668 PM Keyboard Maestro[61312]: (
	0   CoreFoundation                      0x00007fff91cefc72 __exceptionPreprocess + 178
	1   libobjc.A.dylib                     0x00007fff9b80773c objc_exception_throw + 48
	2   CoreFoundation                      0x00007fff91d591ed -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
	3   CoreFoundation                      0x00007fff91c5fcd1 ___forwarding___ + 1009
	4   CoreFoundation                      0x00007fff91c5f858 _CF_forwarding_prep_0 + 120
	5   Keyboard Maestro                    0x000000010cbddee6 _ZL24GetWithPasswordFromEntryP12NSDictionary8AllowNil10KeepDelete + 197
	6   Keyboard Maestro                    0x000000010cbde491 _ZN11KMVariables4ListEv + 430
	7   Keyboard Maestro                    0x000000010caaa54f _ZN9TokenText19FillInsertTokenMenuEP6NSMenuP11objc_objectP13objc_selectorS4_ + 160
	8   Keyboard Maestro                    0x000000010cac4a88 -[KMAppDelegate menuNeedsUpdate:] + 165
	9   AppKit                              0x00007fff89e17014 -[NSMenu _populateFromDelegateWithEventRef:] + 336
	10  AppKit                              0x00007fff89e135a9 -[NSMenu _populateWithEventRef:] + 80
	11  AppKit                              0x00007fff89e16171 -[NSCarbonMenuImpl _carbonPopulateEvent:handlerCallRef:] + 475
	12  AppKit                              0x00007fff89e15e5d NSSLMMenuEventHandler + 708
	13  HIToolbox                           0x00007fff961617be _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 1231
	14  HIToolbox                           0x00007fff96160c48 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 404
	15  HIToolbox                           0x00007fff96160aab SendEventToEventTargetWithOptions + 43
	16  HIToolbox                           0x00007fff961a7fcb _Z16SendMenuPopulateP8MenuDataP20OpaqueEventTargetRefjdjP14OpaqueEventRefhPh + 320
	17  HIToolbox                           0x00007fff961a7d74 _ZL12PopulateMenuP8MenuDataP20OpaqueEventTargetRefP13CheckMenuDatajd + 90
	18  HIToolbox                           0x00007fff961a741b _ZL21Check1MenuForKeyEventP8MenuDataP13CheckMenuData + 226
	19  HIToolbox                           0x00007fff961a7c41 _ZL21Check1MenuForKeyEventP8MenuDataP13CheckMenuData + 2312
	20  HIToolbox                           0x00007fff961a69d3 _ZL21CheckMenusForKeyEventP8MenuDataP13CheckMenuData + 1179
	21  HIToolbox                           0x00007fff961a64c0 _Z15_IsMenuKeyEventP8MenuDataP14OpaqueEventRefjPS0_Pt + 692
	22  HIToolbox                           0x00007fff961a61d4 IsMenuKeyEvent + 110
	23  AppKit                              0x00007fff89e15a96 +[NSCarbonMenuImpl _menuItemWithKeyEquivalentMatchingEventRef:inMenu:] + 327
	24  AppKit                              0x00007fff89e15820 _NSFindMenuItemMatchingCommandKeyEvent + 300
	25  AppKit                              0x00007fff89e00ebf _NSHandleCarbonMenuEvent + 86
	26  AppKit                              0x00007fff89c75e79 _DPSNextEvent + 1906
	27  AppKit                              0x00007fff89c74f62 -[NSApplication _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 454
	28  AppKit                              0x00007fff89c69abc -[NSApplication run] + 682
	29  AppKit                              0x00007fff89c330a4 NSApplicationMain + 1176
	30  Keyboard Maestro                    0x000000010ca5a7b1 main + 155
	31  libdyld.dylib                       0x00007fff91bd95ad start + 1
)
2/4/16 2:31:03.670 PM Keyboard Maestro[61312]: -[__NSCFBoolean isEqualToString:]: unrecognized selector sent to instance 0x7fff78d8ee50
2/4/16 2:31:03.670 PM Keyboard Maestro[61312]: An uncaught exception was raised
2/4/16 2:31:03.670 PM Keyboard Maestro[61312]: -[__NSCFBoolean isEqualToString:]: unrecognized selector sent to instance 0x7fff78d8ee50
2/4/16 2:31:03.672 PM Keyboard Maestro[61312]: (
	0   CoreFoundation                      0x00007fff91cefc72 __exceptionPreprocess + 178
	1   libobjc.A.dylib                     0x00007fff9b80773c objc_exception_throw + 48
	2   CoreFoundation                      0x00007fff91d591ed -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
	3   CoreFoundation                      0x00007fff91c5fcd1 ___forwarding___ + 1009
	4   CoreFoundation                      0x00007fff91c5f858 _CF_forwarding_prep_0 + 120
	5   Keyboard Maestro                    0x000000010cbddee6 _ZL24GetWithPasswordFromEntryP12NSDictionary8AllowNil10KeepDelete + 197
	6   Keyboard Maestro                    0x000000010cbde491 _ZN11KMVariables4ListEv + 430
	7   Keyboard Maestro                    0x000000010cbe9a39 _ZN9Calculate22FillInsertFunctionMenuEP6NSMenuP11objc_objectP13objc_selectorS4_ + 160
	8   Keyboard Maestro                    0x000000010cac4a49 -[KMAppDelegate menuNeedsUpdate:] + 102
	9   AppKit                              0x00007fff89e17014 -[NSMenu _populateFromDelegateWithEventRef:] + 336
	10  AppKit                              0x00007fff89e135a9 -[NSMenu _populateWithEventRef:] + 80
	11  AppKit                              0x00007fff89e16171 -[NSCarbonMenuImpl _carbonPopulateEvent:handlerCallRef:] + 475
	12  AppKit                              0x00007fff89e15e5d NSSLMMenuEventHandler + 708
	13  HIToolbox                           0x00007fff961617be _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 1231
	14  HIToolbox                           0x00007fff96160c48 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 404
	15  HIToolbox                           0x00007fff96160aab SendEventToEventTargetWithOptions + 43
	16  HIToolbox                           0x00007fff961a7fcb _Z16SendMenuPopulateP8MenuDataP20OpaqueEventTargetRefjdjP14OpaqueEventRefhPh + 320
	17  HIToolbox                           0x00007fff961a7d74 _ZL12PopulateMenuP8MenuDataP20OpaqueEventTargetRefP13CheckMenuDatajd + 90
	18  HIToolbox                           0x00007fff961a741b _ZL21Check1MenuForKeyEventP8MenuDataP13CheckMenuData + 226
	19  HIToolbox                           0x00007fff961a7c41 _ZL21Check1MenuForKeyEventP8MenuDataP13CheckMenuData + 2312
	20  HIToolbox                           0x00007fff961a69d3 _ZL21CheckMenusForKeyEventP8MenuDataP13CheckMenuData + 1179
	21  HIToolbox                           0x00007fff961a64c0 _Z15_IsMenuKeyEventP8MenuDataP14OpaqueEventRefjPS0_Pt + 692
	22  HIToolbox                           0x00007fff961a61d4 IsMenuKeyEvent + 110
	23  AppKit                              0x00007fff89e15a96 +[NSCarbonMenuImpl _menuItemWithKeyEquivalentMatchingEventRef:inMenu:] + 327
	24  AppKit                              0x00007fff89e15820 _NSFindMenuItemMatchingCommandKeyEvent + 300
	25  AppKit                              0x00007fff89e00ebf _NSHandleCarbonMenuEvent + 86
	26  AppKit                              0x00007fff89c75e79 _DPSNextEvent + 1906
	27  AppKit                              0x00007fff89c74f62 -[NSApplication _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 454
	28  AppKit                              0x00007fff89c69abc -[NSApplication run] + 682
	29  AppKit                              0x00007fff89c330a4 NSApplicationMain + 1176
	30  Keyboard Maestro                    0x000000010ca5a7b1 main + 155
	31  libdyld.dylib                       0x00007fff91bd95ad start + 1
)
2/4/16 2:31:03.704 PM Keyboard Maestro[61312]: -[__NSCFBoolean isEqualToString:]: unrecognized selector sent to instance 0x7fff78d8ee50
2/4/16 2:31:03.779 PM Keyboard Maestro[61312]: -[__NSCFBoolean isEqualToString:]: unrecognized selector sent to instance 0x7fff78d8ee50
2/4/16 2:31:03.781 PM Keyboard Maestro[61312]: (
	0   CoreFoundation                      0x00007fff91cefc72 __exceptionPreprocess + 178
	1   libobjc.A.dylib                     0x00007fff9b80773c objc_exception_throw + 48
	2   CoreFoundation                      0x00007fff91d591ed -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
	3   CoreFoundation                      0x00007fff91c5fcd1 ___forwarding___ + 1009
	4   CoreFoundation                      0x00007fff91c5f858 _CF_forwarding_prep_0 + 120
	5   Keyboard Maestro                    0x000000010cbddee6 _ZL24GetWithPasswordFromEntryP12NSDictionary8AllowNil10KeepDelete + 197
	6   Keyboard Maestro                    0x000000010cbde491 _ZN11KMVariables4ListEv + 430
	7   Keyboard Maestro                    0x000000010cc6e055 -[PreferencesVariablesController reloadEntries:select:selectNew:] + 690
	8   Keyboard Maestro                    0x000000010cc6d7a1 -[PreferencesVariablesController toolbarViewWillUnhide] + 210
	9   Keyboard Maestro                    0x000000010cc92e26 -[KMToolbarWindowController changeToController:] + 174
	10  Keyboard Maestro                    0x000000010cc9434d -[KMToolbarWindowController SetupWithPane:] + 1618
	11  Keyboard Maestro                    0x000000010cc945ff +[KMToolbarWindowController showToolbar:nibName:windowPane:] + 195
	12  Keyboard Maestro                    0x000000010cab7593 +[KMPreferencesController showPreferencesWindow] + 46
	13  Keyboard Maestro                    0x000000010cac388e -[KMAppDelegate showPreferencesWindow:] + 24
	14  libsystem_trace.dylib               0x00007fff8aea907a _os_activity_initiate + 75
	15  AppKit                              0x00007fff89edec91 -[NSApplication sendAction:to:from:] + 460
	16  AppKit                              0x00007fff89edea2b -[NSMenuItem _corePerformAction] + 336
	17  AppKit                              0x00007fff89ede78b -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 114
	18  libsystem_trace.dylib               0x00007fff8aea907a _os_activity_initiate + 75
	19  AppKit                              0x00007fff89edd679 -[NSMenu performKeyEquivalent:] + 357
	20  AppKit                              0x00007fff89edc81d -[NSApplication _handleKeyEquivalent:] + 920
	21  AppKit                              0x00007fff89e02f82 -[NSApplication sendEvent:] + 4274
	22  AppKit                              0x00007fff89c69b2e -[NSApplication run] + 796
	23  AppKit                              0x00007fff89c330a4 NSApplicationMain + 1176
	24  Keyboard Maestro                    0x000000010ca5a7b1 main + 155
	25  libdyld.dylib                       0x00007fff91bd95ad start + 1
)

Following up myself.

I was able to get Keyboard Maestro working again by deleting the variable (setting it to %Delete%).

I was also able to fix bug by changing the javascript above to convert the value that I set the variable to to a string by changing the HTML to:

        <input onclick="window.KeyboardMaestro.SetVariable('MyTestVar',this.checked.toString())" name="Web_Checkbox" class="input" type="checkbox" id="checkbox" />

Well that’s a nasty bug, I’ll make sure to defend against that case (and similar ones) in the next version.

Thanks.

1 Like

Off topic: Why is SetVariable uppercased? As a function, it should be spelled setVariable.

I was not aware JavaScript imposed a naming convention on functions…?

I generally would use UpperCamelCase for the most part in everything except Objective C. Hence its done that way.

It does appear that DOM usage is generally LowerCamelCase.

And speaking of which, since when does CamelCase imply LowerCamelCase. Wikipedia says CamelCase implies LowerCamelCase, but then every historic example of the use uses UpperCamelCase (DryIce Corporation, CinemaScope, VistaVision, ShopKo, MisterRogers. AstroTurf, ConAgra).

In any event, the reason it is written that way is because I use PascalCase/UpperCamelCase for everything except Objective C.

Fair enough. I mostly use Python, JS and CoffeeScript day to day, so am used to everything beginning with a lowercase letter unless it’s a class, which always starts with an uppercase letter. I consider that the de facto standard in JS, but then, who am I to say what’s what. No worries, and sorry to have stated my opinion like it was a matter of fact.

There seems to be some confusion around camelCase or CamelCase, but I don’t know which is correct. At the end of the day, you wrote it your way, and that’s fine. It just really threw me at first, as I only remembered the name, and it didn’t work.

1 Like