I occasionally get the following error when a Steam window is opened after Hammerspoon (v0.9.24) was loaded:
(but not when steam is opened before Hammerspoon is loaded)
...poon.app/Contents/Resources/extensions/hs/hints/init.lua:80: attempt to index a nil value
stack traceback:
...poon.app/Contents/Resources/extensions/hs/hints/init.lua:80: in function 'displayHintsForDict'
...poon.app/Contents/Resources/extensions/hs/hints/init.lua:174: in function <...poon.app/Contents/Resources/extensions/hs/hints/init.lua:149>
[C]: in function 'xpcall'
...oon.app/Contents/Resources/extensions/hs/hotkey/init.lua:23: in function <...oon.app/Contents/Resources/extensions/hs/hotkey/init.lua:21>
This is very odd, it looks, from the code, like either the Steam window has no :screen() value, or the screen has no :frame() value, neither of which should be possible!
How occasionally does it happen? I guess I need to install Steam and see if I can reproduce :)
I'm not sure about the regularity - tried it now and it didn't misbehave, on other occasions, it crashes regularly.
More information: the steam window cannot be controlled using Hammerspoon - trying to move/resize it doesn't work (the window flickers, shows an image on the target location, and returns to the original position - it may or may not be related).
This will be fixed when #256 lands :)
Now I know which app was causing my problems :P
I had Steam running as well.
This seems to be biting me with PhpStorm. This code in init.lua:
hs.hotkey.bind(hyper, "Up", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x
f.y = max.y
f.w = max.w
f.h = max.h
win:setFrame(f)
end)
Results in this console output:
/Users/travis/.hammerspoon/init.lua:125: attempt to index a nil value (local 'win')
stack traceback:
/Users/travis/.hammerspoon/init.lua:125: in function </Users/travis/.hammerspoon/init.lua:121>
stack traceback:
I'm very new to Hammerspoon, but I dug around and found the id of the window object I'm trying to operate on, and it looks like it indeed doesn't have a :frame() value.
Any suggestions on a workaround? Or, any ways I can provide better debug info and possibly help fix this behavior? Like I said, I'm new to Hammerspoon (and Lua), but I'm happy to try to put together a PR if someone can point me in the right direction.
@tnorthcutt Your issue is unrelated to this Github issue, but that's okay, I'm happy to attempt to help.
attempt to index a nil value (local 'win') sounds more like win is nil, which would happen if you used this shortcut without a focused window, which can happen sometimes on OSX.
@tnorthcutt if the problem is hs.window.focusedWindows() returns nil, try using hs.window.frontmostWindow() instead; otherwise, to debug easily from the console, you can use hs.window.find() (or just hs.window()) with part of the title; for example (I use the Hammerspoon Console window itself in this example, substitute in the first command acordingly):
> w=hs.window'console'
> w
hs.window: Hammerspoon Console (0x7fc887a9e018)
> w:frame()
hs.geometry.rect(2688.0,23.0,1152.0,1066.0)
If w is nil, then no window was found; if w is valid, but w:frame() returns nil, then it's a different problem that needs further scrutiny.
@trishume @lowne thanks for the replies. Unfortunately this is both an issue of hs.window.focusedWindow() returning a window object, but that object not having a :frame() object (I hope my terminology is correct), and it being an intermittent issue, which I can't reproduce this time. I'll try some more things to get it reproducible then try those suggestions @lowne.
Cheers!
This popped up again today, so I tried switching to frontmostWindow() as per @lowne's suggestion, and it worked! Thanks for the help.
I was experiencing similar issues in OSX for both focusedWindow() and frontmostWindow() returning nil, and found this solution:
which suggests going to:
System Preferences > Security & Privacy > Privacy tab > Accessibility
and then check the box to allow Hammerspoon to control your computer
Most helpful comment
I was experiencing similar issues in OSX for both
focusedWindow()andfrontmostWindow()returning nil, and found this solution:https://stackoverflow.com/questions/34743870/lua-hammerspoon-hs-window-focusedwindow-is-nil-when-assigned-to-a-variable
which suggests going to:
System Preferences>Security & Privacy>Privacytab >Accessibilityand then check the box to allow
Hammerspoonto control your computer