Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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