fix(hammerspoon/app_toggle): find only legit GUI apps

- Fixes an issue with `* Web Content` processes raising an error when checking their path.
- Restrict list of running apps to those who's path ends with `.app`, effectively filtering out background processes and services.
This commit is contained in:
2025-08-19 09:44:59 +01:00
parent fb2da8181b
commit 4e7a48fb2c

View File

@@ -10,8 +10,20 @@ local obj = {}
local function findRunningApp(name, path)
for _, app in ipairs(hs.application.runningApplications()) do
if app:name() == name and (path == nil or path == app:path()) then
return app
local appName = app:name()
-- Skip "* Web Content" apps as calling `app:path()` on them often returns
-- an error.
if appName and not appName:match(" Web Content$") then
local appPath = app:path()
-- Skip apps that don't have a path or that don't end with ".app". If the
-- path doesn't end with ".app", it's not likely to be a GUI app.
if appPath and appPath:match("%.app$") then
if appName == name and (path == nil or path == appPath) then
return app
end
end
end
end
end