mirror of
https://github.com/jimeh/dotfiles.git
synced 2026-02-19 06:46:40 +00:00
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:
@@ -10,8 +10,20 @@ local obj = {}
|
|||||||
|
|
||||||
local function findRunningApp(name, path)
|
local function findRunningApp(name, path)
|
||||||
for _, app in ipairs(hs.application.runningApplications()) do
|
for _, app in ipairs(hs.application.runningApplications()) do
|
||||||
if app:name() == name and (path == nil or path == app:path()) then
|
local appName = app:name()
|
||||||
return app
|
|
||||||
|
-- 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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user