If I call:
local windows = hs.window.focusedWindows()
I get this error:
attempt to index a nil value (global 'uielement')
I am seeing this issue with 0.9.79 and 0.9.80 - prior to that it works fine.
I don't know if there's any connection to this GitHub issue:
But I have checked my accessibility settings and Hammerspoon does have permission. Let me know if I can provide further information.
The actual function should be hs.window.focusedWindow() (no s at the end).
That said, the uielement error has been noted and will hopefully be fixed soon... https://github.com/Hammerspoon/hammerspoon/pull/2488#issuecomment-696510174
Oh I'm sorry for the typo! So I guess the issue I'm seeing is the the fnutils.filter bit?
local windows = hs.window.focusedWindow()
test = hs.fnutils.filter(windows, hs.window.isStandard)
hs.window.focusedWindow() returns a single hs.window object -- the one with the current focus (usually the frontmost window that is able to take input from the mouse and/or keyboard).
hs.fnutils.filter is expecting its first argument to be a table, not an element, so you could in theory do hs.fnutils.filter({ windows },... but that would still limit its checking to the one window returned by focusedWindow().
If you're wanting a table of all windows currently on the screen, you should use hs.window.allWindows(), or if all the windows for a specific application, something like app:allWindows() (where app is an hs.application object; app = hs.application("Hammerspoon") or app = hs.application.frontmostApplication(), for example) instead.
Thanks for looking at this @asmagill. I think we can close this now the PR is merged.
@asmagill thanks for the pointers! So this should work right?
local appWithFocus = hs.application.frontmostApplication()
local appWithFocusWindows = appWithFocus:allWindows()
test = hs.fnutils.filter(appWithFocusWindows, hs.window.isStandard)
in 0.9.80 it throws the:
attempt to index a nil value (global 'uielement')
and in 0.9.78 it works. So I assume that the fix from 2488 will resolve this one?
Thanks again - sorry to add to the closed issue - just wanted to make sure I'm not doing something dumb (again).
Close... first, yes, the uielement issue should be fixed in master. What you should see is an error thrown by hs.fnutils that it expects a function as the second argument, rather than what hs.window.isStandard should be resolving to -- nil, because of: second, isStandard is a method, not defined at the hs.window module level but for hs.window object instances... the following should work:
~lua
local appWithFocus = hs.application.frontmostApplication()
local appWithFocusWindows = appWithFocus:allWindows()
test = hs.fnutils.filter(appWithFocusWindows, function(w) return w:isStandard() end)
~
So close :) thank you so much for putting up with me :)
You're a star
Most helpful comment
Close... first, yes, the
uielementissue should be fixed in master. What you should see is an error thrown byhs.fnutilsthat it expects a function as the second argument, rather than whaths.window.isStandardshould be resolving to --nil, because of: second,isStandardis a method, not defined at thehs.windowmodule level but forhs.windowobject instances... the following should work:~lualocal appWithFocus = hs.application.frontmostApplication()
local appWithFocusWindows = appWithFocus:allWindows()
test = hs.fnutils.filter(appWithFocusWindows, function(w) return w:isStandard() end)
~