I want to use hammerspoon to find one specific chrome tab across al chrome windows across all spaces. The only way I was able to achieve this was using osascript, which I don't like much because it means to use a big multi-line string inside Lua. I will prefer to use native hammerspoon methods with Lua.
Just in case, here is my version using osascript that works perfectly:
local function osa()
local tabName = "whatsapp"
local script = [[
tell application "Google Chrome" to activate
tell application "Google Chrome"
set found to false
repeat with theWindow in windows
repeat with theTab in (tabs of theWindow)
if the title of theTab contains "%s" then
set found to true
set index of theWindow to 1
return id of theTab
end if
end repeat
end repeat
return found
end tell
]]
local success, windowID, errors = hs.osascript.applescript(string.format(script, tabName))
print(success, windowID, type(windowID), hs.inspect(errors))
if success == false then
hs.alert.show("Tab with name '" .. tabName .. "' not found.")
else
hs.alert.show("Tab '" .. tabName .. "' found and brought to front.")
end
end