Hammerspoon / hammerspoon

Staggeringly powerful macOS desktop automation with Lua

Home Page:http://www.hammerspoon.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Version v0.9.96 breaks hs.window.filter.new

Grazfather opened this issue · comments

> hs.window.filter.new(nil)
2022-03-29 09:36:27: -- Loading extensions: window.filter
...merspoon.app/Contents/Resources/extensions/hs/spaces.lua:71: attempt to index a nil value (local 'contents')
stack traceback:
	...merspoon.app/Contents/Resources/extensions/hs/spaces.lua:71: in local 'getDockExitTemplates'
	...merspoon.app/Contents/Resources/extensions/hs/spaces.lua:76: in main chunk
	[C]: in function 'rawrequire'
	...poon.app/Contents/Resources/extensions/hs/_coresetup.lua:662: in function 'require'
	...n.app/Contents/Resources/extensions/hs/window_filter.lua:1530: in main chunk
	[C]: in function 'rawrequire'
	...poon.app/Contents/Resources/extensions/hs/_coresetup.lua:662: in function 'require'
	(...tail calls...)
	[C]: in function 'rawrequire'
	...poon.app/Contents/Resources/extensions/hs/_coresetup.lua:662: in function 'require'
	...merspoon.app/Contents/Resources/extensions/hs/window.lua:1027: in function <...merspoon.app/Contents/Resources/extensions/hs/window.lua:1025>
	(...tail calls...)
	[string "return hs.window.filter.new(nil)"]:1: in main chunk
	[C]: in function 'xpcall'
	...poon.app/Contents/Resources/extensions/hs/_coresetup.lua:525: in function <...poon.app/Contents/Resources/extensions/hs/_coresetup.lua:505>

Calling it with anything seems to crash. Haven't investigated.

This is on Big Sur v11.6.3, Intel

commented

+1

Upgraded last night but have not run into any issues so far. Running OS X Monterey

Exactly the same crash caused by window.filter on my Big Sur mac as well.

@Grazfather out of interest, have you previously used a tool like CleanMyMac to strip translations from macOS to save space?

I'm not really sure why spaces.lua is even involved here, but around line 71 it's trying to find a file of strings in the Dock.app bundle.

FWIW I can't reproduce the traceback you're seeing. I don't use either hs.window.filter or hs.spaces so neither is in my init.lua:

> hs.window.filter.new(nil)
2022-03-29 22:30:43: -- Loading extensions: window.filter
hs.window.filter: ... (0x600000d21d80)

@asmagill any ideas on this?

Hah! I found the issue.

Instead of finding Dock.app, it's finding Docker.app, which doesn't have that file.

application("Dock"):path() is the problem.

> require("hs.application")("Dock")
hs.application: Docker (0x600001373838)	hs.application: Dock (0x60000137f6b8)	hs.application: Dock Extra (0x60000137d838)```

Swapping it out with:

hs.application.applicationsForBundleID("com.apple.dock")[1]

...should do the trick?

@Grazfather aha, good catch!
@latenitefilms exactly that. Preparing a PR now :)

Confirmed that that fixes the issue

> hs.window.filter.new(nil)
2022-03-29 18:10:06: -- Loading extensions: window.filter
hs.window.filter: ... (0x600001c03b80)

@Grazfather a signed dev build with the fix will appear shortly here: https://github.com/Hammerspoon/hammerspoon/actions/runs/2061396652

I would very much appreciate it if you could give it a try and confirm the fix has worked. Thanks for reporting!

commented

The bundle contents of the Dock are used to determine what Mission Control calls space names when it's being displayed (so it can delete them appropriately). And yes, specifying by bundle id should fix that issue.

I wonder, though, if hs.application.find should sort the results such that exact matches come first or maybe take an optional parameter to limit it to exact matches (I just discovered that hs.application.find will take a lua style regular expression, so I should have been doing hs.application("^Dock$")).

commented

And spaces is used by window filter to watch for space changes to identify windows on other spaces.

I really need to rewrite hs.window.filter now -- with the additions to hs.spaces and the addition of hs.axuielement, the module is in dire need of a complete overhaul.

@asmagill Any objections if I push out 0.9.97 with the current fix for this?

commented

Go for it

Sorry I couldn't verify with the release, but I had manually copied in the change and it was good. Downloaded the new release and I can (re) confirm that things work well.

Thanks for the quick turnaround!