Skip to content

Instantly share code, notes, and snippets.

@linktohack
Created August 24, 2021 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linktohack/dd720ff96996122ff6e24bbd35b988f4 to your computer and use it in GitHub Desktop.
Save linktohack/dd720ff96996122ff6e24bbd35b988f4 to your computer and use it in GitHub Desktop.
HAMMERSPOOL Clock item in menubar
local clockingLog = hs.logger.new("clocking")
local clockingMenu = hs.menubar.new()
local currentTask = nil
local function trim(s)
return (s:gsub("^%s*(.-)%s*$", "%1"))
end
local function eval(sexp, callback)
hs.task.new(
"/usr/local/bin/emacsclient",
function(exitCode, stdOut, stdErr)
if exitCode == 0 then
callback(trim(stdOut))
end
end,
{ "--eval", sexp }
):start()
end
local function updateClockingMenu()
eval(
"(org-clock-is-active)",
function(value)
if value == "nil" then
eval("org-pomodoro-mode-line",
function(value)
if value == "nil" then
clockingMenu:setTitle("No Task")
else
eval(
"(substring-no-properties (nth 1 org-pomodoro-mode-line))",
function(value)
clockingMenu:setTitle(string.match(value, '"(.+)"'))
end
)
end
end)
else
eval(
"(org-clock-get-clock-string)",
function(value)
clockingMenu:setTitle(string.match(value, '"(.+)"'))
end
)
end
end
)
end
local function startUpdatingClockingMenu()
currentTask = hs.timer.doEvery(10, updateClockingMenu)
end
local mod = {}
function mod.init()
updateClockingMenu()
startUpdatingClockingMenu()
end
return mod
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment