Skip to content

Instantly share code, notes, and snippets.

@apiarian
Last active February 16, 2023 03:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apiarian/23e1d06f67345525bd976616b0aa659a to your computer and use it in GitHub Desktop.
Save apiarian/23e1d06f67345525bd976616b0aa659a to your computer and use it in GitHub Desktop.
pingcheck = hs.menubar.new()
function pingUpdate()
pingcheck:setTitle('⥌'..pingcheck:title())
local p = hs.network.ping('example.com', 3)
hs.timer.doAfter(4, function()
p:cancel()
local avg = p:summary():match('%/(%d+)%.%d+%/')
if avg == nil or avg == '0' then
pingcheck:setTitle('∞')
else
pingcheck:setTitle(avg..'ms')
end
end)
end
pingcheck:setTitle('ping')
hs.timer.doEvery(5, pingUpdate)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment