From 4e7a48fb2c3302e2c03339e1400cdb8092d6057b Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Tue, 19 Aug 2025 09:44:59 +0100 Subject: [PATCH] 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. --- hammerspoon/app_toggle.lua | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/hammerspoon/app_toggle.lua b/hammerspoon/app_toggle.lua index 79d6d29..cf12d86 100644 --- a/hammerspoon/app_toggle.lua +++ b/hammerspoon/app_toggle.lua @@ -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