mirror of
https://github.com/jimeh/dotfiles.git
synced 2026-02-19 13:46:41 +00:00
fix(hammerspoon/app_toggle): enhance app name matching to include sanitized names
This commit is contained in:
@@ -10,10 +10,11 @@ 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
|
||||||
-- Get app name, removing any non-printable characters. This specifically
|
-- Get app name, and also get a sanitized version of the name by removing
|
||||||
-- fixes WhatsApp, who's name starts with a invisible UTF-8 LRM control
|
-- any non-printable characters. Some apps like WhatsApp have names that
|
||||||
-- character.
|
-- contain invisible characters that cause the app to not be found.
|
||||||
local appName = app:name():gsub('[^%g+]', '')
|
local appName = app:name()
|
||||||
|
local sanitizedAppName = appName:gsub('[^%g+]', '')
|
||||||
|
|
||||||
-- app:path() can error for certain pseudo-apps.
|
-- app:path() can error for certain pseudo-apps.
|
||||||
-- Guard with pcall and skip on failure to keep iterating.
|
-- Guard with pcall and skip on failure to keep iterating.
|
||||||
@@ -23,10 +24,10 @@ local function findRunningApp(name, path)
|
|||||||
|
|
||||||
-- Skip apps that don't have a path or that don't end with ".app". If the
|
-- 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.
|
-- path doesn't end with ".app", it's not likely to be a GUI app.
|
||||||
if ok and appPath and appPath:match("%.app$") then
|
if ok and appPath and appPath:match("%.app$")
|
||||||
if appName == name and (path == nil or path == appPath) then
|
and (appName == name or sanitizedAppName == name)
|
||||||
return app
|
and (path == nil or path == appPath) then
|
||||||
end
|
return app
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user