Stopwatch Menubar for Mac

Not necessarily NetSuite-specifically related, but a helpful tool I made for tracking time for my NetSuite work:

to make it visible press Cmd + Alt + Ctrl + S
to pause Cmd + Alt + Ctrl + P
to reset Cmd + Alt + Ctrl + R

Also clicking it will pause/start the stopwatch.

You’ll need HammerSpoon to see this appear in your top menu bar. To install https://www.hammerspoon.org/ and add the configuration to use it:


-- Stopwatch by robert@netsuiteguide.com --

local super = {"ctrl", "alt", "cmd"}
local hotkey = "S"
local hotkey_pause = "P"
local hotkey_reset = "R"
-- set this to true to always show the menu bar item
-- (making the keyboard shortcut superfluous):
local alwaysShow = false
-- Setup {{{1

local updateTimer, updateMenu, start, pause, reset
local isActive = false
local duration = 0
local timeLeft = duration * 60
local timer = hs.timer.new(1, function() updateTimer() end)


updateTimer = function()-- {{{1
    if not isActive then return end
    timeLeft = timeLeft + 1
    updateMenu()
end-- }}}1


updateMenu = function()-- {{{1
    if not menu then
        menu = hs.menubar.new()
        menu:setTooltip("Stopwatch")
    end
    menu:returnToMenuBar()
    local hours = math.floor(timeLeft / (60*60))
    local minutes = math.floor(timeLeft / 60)
    local minutes_minus_hr = math.floor(timeLeft / 60)- (hours*60) 
    local seconds = timeLeft - (minutes * 60)
    local string = string.format("%0d:%02d:%02d ⏱️", hours, minutes_minus_hr, seconds)
    menu:setTitle(string)

    if isActive then
        menu:setClickCallback(function() pause() end)
    end

    if not isActive then
        menu:setClickCallback(function() start() end)
    end
    
end-- }}}1


start = function()-- {{{1
    if isActive then return end
    timer:start()
    isActive = true
end-- }}}1

pause = function()-- {{{1
    if not isActive then return end
    timer:stop()
    isActive = false
    updateMenu()
end-- }}}1

reset = function()-- {{{1
    timeLeft = duration * 60
    updateMenu()
end-- }}}1



hs.hotkey.bind(super, hotkey, function() start() end)
hs.hotkey.bind(super, hotkey_pause, function() pause() end)
hs.hotkey.bind(super, hotkey_reset, function() reset() end)
if alwaysShow then updateMenu() end