asmagill / hs._asm.axuielement

Accessing Accessibility Objects with Hammerspoon
33 stars 2 forks source link

Consistently receiving NSInvalidArgumentException: +[LuaSkin sharedWithState:]: unrecognized selector #21

Closed megalithic closed 4 years ago

megalithic commented 4 years ago

First of all, thank you so much for providing these libraries for us to use with Hammerspoon, @asmagill!!

I'm on macOS Catalina 10.15.4, and Hammerspoon version 0.9.78 (5164).

I'm just using the pre-compiled binary, extracting to my ~/.hammerspoon directory and referencing like so: local axuiWindowElement = require('hs._asm.axuielement').windowElement for getting attributeValues.

I also am unable to make install successfully from source. I have the latest XCode (from the App Store) and command-line tools installed, too.

I saw many of the posts about coroutines in Lua/LuaSkin, but not seeing a way, for the lay-person to get these sorts of things working.

Might you have any insight?

Thanks again @asmagill!

Here's the error output from the Hammerspoon console with the aforementioned require added to my ~/.hammerspoon/init.lua:

2020-05-12 08:33:15: *** ERROR: NSInvalidArgumentException: +[LuaSkin sharedWithState:]: unrecognized selector sent to class 0x10afe2e30
(
    0   CoreFoundation                      0x00007fff39873d07 __exceptionPreprocess + 250
    1   libobjc.A.dylib                     0x00007fff725975bf objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff398f2be7 __CFExceptionProem + 0
    3   CoreFoundation                      0x00007fff397d857b ___forwarding___ + 1427
    4   CoreFoundation                      0x00007fff397d7f58 _CF_forwarding_prep_0 + 120
    5   internal.so                         0x0000000112a04eb7 luaopen_hs__asm_axuielement_internal + 39
    6   LuaSkin                             0x000000010afce024 luaD_precall + 681
    7   LuaSkin                             0x000000010afce186 luaD_call + 52
    8   LuaSkin                             0x000000010afce1d3 luaD_callnoyield + 21
    9   LuaSkin                             0x000000010afc7cea lua_callk + 132
    10  LuaSkin                             0x000000010afbb9a4 ll_require + 447
    11  LuaSkin                             0x000000010afce024 luaD_precall + 681
    12  LuaSkin                             0x000000010afca1d4 luaV_execute + 708
    13  LuaSkin                             0x000000010afce192 luaD_call + 64
    14  LuaSkin                             0x000000010afce1d3 luaD_callnoyield + 21
    15  LuaSkin                             0x000000010afc7cea lua_callk + 132
    16  LuaSkin                             0x000000010afbb9a4 ll_require + 447
    17  LuaSkin                             0x000000010afce024 luaD_precall + 681
    18  LuaSkin                             0x000000010afca1d4 luaV_execute + 708
    19  LuaSkin                             0x000000010afce192 luaD_call + 64
    20  LuaSkin                             0x000000010afce1d3 luaD_callnoyield + 21
    21  LuaSkin                             0x000000010afc7cea lua_callk + 132
    22  LuaSkin                             0x000000010afbb9a4 ll_require + 447
    23  LuaSkin                             0x000000010afce024 luaD_precall + 681
    24  LuaSkin                             0x000000010afca1d4 luaV_execute + 708
    25  LuaSkin                             0x000000010afce192 luaD_call + 64
    26  LuaSkin                             0x000000010afce1d3 luaD_callnoyield + 21
    27  LuaSkin                             0x000000010afb9fd2 luai_objcttry + 28
    28  LuaSkin                             0x000000010afce6d0 luaD_pcall + 110
    29  LuaSkin                             0x000000010afc7e20 lua_pcallk + 236
    30  LuaSkin                             0x000000010afcd5ae luaB_xpcall + 115
    31  LuaSkin                             0x000000010afce024 luaD_precall + 681
    32  LuaSkin                             0x000000010afca1d4 luaV_execute + 708
    33  LuaSkin                             0x000000010afce192 luaD_call + 64
    34  LuaSkin                             0x000000010afce1d3 luaD_callnoyield + 21
    35  LuaSkin                             0x000000010afb9fd2 luai_objcttry + 28
    36  LuaSkin                             0x000000010afce6d0 luaD_pcall + 110
    37  LuaSkin                             0x000000010afc7e20 lua_pcallk + 236
    38  Hammerspoon                         0x000000010ac90852 MJLuaInit + 2189
    39  libdispatch.dylib                   0x00007fff736e46c4 _dispatch_call_block_and_release + 12
    40  libdispatch.dylib                   0x00007fff736e5658 _dispatch_client_callout + 8
    41  libdispatch.dylib                   0x00007fff736f0cab _dispatch_main_queue_callback_4CF + 936
    42  CoreFoundation                      0x00007fff39837041 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    43  CoreFoundation                      0x00007fff397f6e47 __CFRunLoopRun + 2028
    44  CoreFoundation                      0x00007fff397f5ffe CFRunLoopRunSpecific + 462
    45  HIToolbox                           0x00007fff38429abd RunCurrentEventLoopInMode + 292
    46  HIToolbox                           0x00007fff384296f4 ReceiveNextEventCommon + 359
    47  HIToolbox                           0x00007fff38429579 _BlockUntilNextEventMatchingListInModeWithFilter + 64
    48  AppKit                              0x00007fff36a74c99 _DPSNextEvent + 883
    49  AppKit                              0x00007fff36a734e0 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1352
    50  AppKit                              0x00007fff36a651ee -[NSApplication run] + 658
    51  AppKit                              0x00007fff36a36ff6 NSApplicationMain + 777
    52  libdyld.dylib                       0x00007fff7373ecc9 start + 1
)

UPDATE

Closing.. building Hammerspoon in debug seemed to do the trick; further reading about the coroutines and LuaSkin sharedWithState changes shows that I need 0.9.79+ (or build Hammerspoon locally).

asmagill commented 4 years ago

Ok, so if I'm following correctly, you were finally able to compile Hammerspoon and get this to work?

I do want to apologize about the current state of the axuielement module examples... I'm in the process of cleaning things up and making the module take advantage of the fact that the upcoming release of Hammerspoon (or development build, if you have XCode) properly supports coroutines... because most applications that utilize the accessibility features have literally hundreds if not thousands of accessibility elements within them, things can get really slow and prior to fixing coroutines, this meant potentially blocking behavior within Hammerspoon which slowed everything down. However, to properly utilize coroutines, the search and filter methods have to be written to use a callback to notify you when they have completed.

The core functionality is solid, so if you know what elements you're looking for it works well... for example, since application menu items are always in the "AXMenuBar" attribute which is a direct child of the application element itself, this code can replace hs.application:getMenuItems and it doesn't lock up Hammerspoon while grabbing the items.

What currently doesn't work are the exploratory queries in some of the module support documents, though I hope to fix those and update the examples over the next couple of days.