Looks like the new Hammerspoon breaks axuielement:
> require("hs._asm.axuielement")
error loading module 'hs._asm.axuielement.internal' from file '/Users/jdsmith/.hammerspoon/hs/_asm/axuielement/internal.so':
dlopen(/Users/jdsmith/.hammerspoon/hs/_asm/axuielement/internal.so, 6): Symbol not found: _lua_newuserdata
Referenced from: /Users/jdsmith/.hammerspoon/hs/_asm/axuielement/internal.so
Expected in: /Applications/Hammerspoon.app/Contents/MacOS/../Frameworks/LuaSkin.framework/Versions/A/LuaSkin
in /Users/jdsmith/.hammerspoon/hs/_asm/axuielement/internal.so
stack traceback:
[C]: in ?
[C]: in function 'rawrequire'
...app/Contents/Resources/extensions/hs/_coresetup/init.lua:651: in function 'require'
/Users/jdsmith/.hammerspoon/hs/_asm/axuielement/init.lua:27: in main chunk
[C]: in function 'rawrequire'
...app/Contents/Resources/extensions/hs/_coresetup/init.lua:651: in function 'require'
(...tail calls...)
[C]: in function 'xpcall'
...app/Contents/Resources/extensions/hs/_coresetup/init.lua:514: in function <...app/Contents/Resources/extensions/hs/_coresetup/init.lua:494>
I downloaded the recent release of axuielement (v1.0.7.3), but the same error persists. Thanks.
If you're using Hammerspoon v 0.9.79 or newer (i.e. a release that have come out in the last week), then you don't need this external module anymore -- it's already there as hs.axuielement.
If you're still using 0.9.78, waiting for our firestorm of hs.window.filter, etc. issues to be cleaned up, then you need https://github.com/asmagill/hs._asm.axuielement/blob/master/axuielement-v1.0.7.3.release.tar.gz (and it should also load as hs.axuielement, though you'll need to explicitly require it as the Hammerspoon autoloader only sees built-in modules) and you'll need to make sure to remove it after upgrading Hammerspoon to a newer version, because the change from Lua 5.3 (in 0.9.78) to Lua 5.4 (in later versions) makes the version at the specific URL I give binary-incompatible with later versions of Hammerspoon.
Oh, and if you've been a long time user of hs._asm.axuielement (which upon re-reading your issue, sounds like you might be), make sure to re-scan the documentation as there have been a few syntax changes made, depending upon how far back you started using the module.
Going forward, now that it's in core, there shouldn't be any more changes to syntax (fingers crossed) -- at least efforts will be made to create wrappers if there are...
OK, that makes sense. I'm on 0.9.80. I can work around loading the (now defunct?) hs._asm.axuielement by checking if hs.axuielement exists, something like:
local hasAX, ax
if hs.axuielement then -- axuielement was moved to hs as of 0.9.79
ax = hs.axuielement
hasAX=true
else
hasAX, ax = pcall(require,"hs._asm.axuielement")
end
For the API itself, is there a simple replacement for calls like:
obj.dockAX = ax.applicationElement(hs.application("Dock")):searchPath({role="AXApplication"})
Failing that, is there a set of examples of using the new elementSearch method and the elementSearchObject it returns? This seems to be very powerful, but asynchronous and quite a bit different than the older API...
Here's a basic example:
hs.openConsole() -- Open the Hammerspoon Console
hammerspoonPID = hs.processInfo["processID"] -- Get the Hammerspoon Process Identifier
element = hs.axuielement.applicationElementForPID(hammerspoonPID) -- Get the AXUIelement for the Hammerspoon application
criteria = "AXWindow" -- Set a criteria - see: http://www.hammerspoon.org/docs/hs.axuielement.html#matchesCriteria
criteriaFunction = hs.axuielement.searchCriteriaFunction(criteria) -- Set a criteria function - see: http://www.hammerspoon.org/docs/hs.axuielement.html#searchCriteriaFunction
callback = function(message, results, numberOfItems) -- Setup a callback - see: http://www.hammerspoon.org/docs/hs.axuielement.html#elementSearch
print(string.format("Message: %s", message)) -- Will return "completed"
print(string.format("Results: %s", hs.inspect(results))) -- Will return a table with a single `AXWindow`
print(string.format("Number of Items: %s", numberOfItems)) -- Will return the number 1 (as there's only one `AXWindow` in the table above)
end
searchObject = element:elementSearch(callback, criteriaFunction) -- Starts the element search based on the above callback and criteria
print(string.format("Is the Search Object Running: %s", searchObject:isRunning())) -- Demonstrates the search object is running
Thanks for that @latenitefilms. Is searchObject fronting for a coroutine? Any recommendations to avoid "callback hell"?
I opened a new issues #2536 on the missing searchPath.
Most helpful comment
Oh, and if you've been a long time user of
hs._asm.axuielement(which upon re-reading your issue, sounds like you might be), make sure to re-scan the documentation as there have been a few syntax changes made, depending upon how far back you started using the module.Going forward, now that it's in core, there shouldn't be any more changes to syntax (fingers crossed) -- at least efforts will be made to create wrappers if there are...