I use an automation software called hammerspoon on osx.
When I use the following code in hammerspoon's console, win
is nil:
> local win = hs.window.focusedWindow()
> win
nil
But actually the function returns some value:
> hs.window.focusedWindow()
hs.window: Hammerspoon Console (0x60000025f798)
This strange behavior breaks all window moving/sizing functions such as:
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "H", function()
local win = hs.window.focusedWindow()
local f = win:frame()
f.x = f.x - 10
win:setFrame(f)
end)
Hammerspoon gives this error:
/Users/mertnuhoglu/.hammerspoon/init.lua:6: attempt to index a nil value (local 'win')
stack traceback:
/Users/mertnuhoglu/.hammerspoon/init.lua:6: in function </Users/mertnuhoglu/.hammerspoon/init.lua:4>
stack traceback:
I don't know if this problem is caused by my computer or something else.
I have osx yosemite, version 10.10.5 and hammerspoon 0.9.43.
Update:
I found solution of the error. It is due to Privacy settings of osx.
Solution:
Prefences > Security > Privacy > Allow Apps: Hammerspoon
But still, I don't understand why hs.window.focusedWindow()
returns something if it is not assigned to a variable and it returns nil
when it is assigned to a variable.