I am using Hammerspoon as a window manager. I have shortcuts that put the window in each corner.
Initially everything works. However, sometimes after sleep/waking the computer .focusedWindow() starts returning nil for specific applications.
Finding the window with hs.window.allWindows() and doing .focus() on it works. However, focusedWindow() still returns nil.
I am having this issue for PyCharm.
note: I have seen comments that Hammerspoon doesn't work on X11 apps but I don't think PyCharm is X11.
Jetbrains apps seem to do weird things with windows - see here: https://github.com/Hammerspoon/hammerspoon/issues/736#issuecomment-184962738
Someone will need to breakpoint/debug the focusedWindow method when using IntelliJ/PyCharm.
it's not just X11 apps - anything that entirely avoids the OSX accessibility stuff is very hard to interact with. What does hs.window.frontmostWindow() do?
If you manualy get the window with pid (getApplication) then you can set the frame without issue.
I have the same problem. Window's moving hotkeys work with hammerspoon's console only.
And I also can't enable accessibility for hammerspoon app. Dot becomes yellow every time I quit hs.
But green one doesn't make window's functions work.
sudo sqlite3 /Library/Application Support/com.apple.TCC/TCC.db 'select * from access where client like "%hammerspoon%"'
gives me " kTCCServiceAccessibility|org.hammerspoon.Hammerspoon|0|0|1|| "
I have 0.9.45 hs version and os 10.11.4
Can anyone try whether using a "focused" windowfilter works around the problem?
focusedwf=hs.window.filter.new{default={focused=true}}:keepActive()
[...]
function f(...)
--local w=hs.window.focusedWindow() --instead:
local w=focusedwf:getWindows()[1]
[...]
end
It doesn't work for me
focusedwf=hs.window.filter.new{default={focused=true}}:
function nudgeRight()
--local win = hs.window.focusedWindow()
local win = focusedwf:getWindows()[1]
local f = win:frame()
saved.win = win
saved.winframe = saved.win:frame()
f.x = f.x + 10
win:setFrame(f)
end
now "attempt to index a nil value (local 'win')" is in "local f = win:frame()"
I see this every time I first launch hammerspoon. If I don't focus a window after launching, hs.window.focusedWindow() returns nil.
I reinstalled OS. No problems with accessibility now and windows movement work fine.
I see this every time I first launch hammerspoon. If I don't focus a window after launching, hs.window.focusedWindow() returns nil.
I wonder if that's related to #651?
@chdiza That was my thought too
I'm trying to clean up our list of issues. This one hasn't had any activity for a year, so I'm going to close it. Please re-open, or file a new issue if you are experiencing this specific issue.
osx: hs.window.focusedWindow() returns with nil until has not given right in system preferences/security/accessibility/privacy
@glendvai Thank you!!! worked for me.
Most helpful comment
osx: hs.window.focusedWindow() returns with nil until has not given right in system preferences/security/accessibility/privacy