Skip to content

Instantly share code, notes, and snippets.

@jishnurajendran
Last active October 27, 2024 13:39
Show Gist options
  • Save jishnurajendran/b697cf3d7b5abe7dc1778d8308a509e5 to your computer and use it in GitHub Desktop.
Save jishnurajendran/b697cf3d7b5abe7dc1778d8308a509e5 to your computer and use it in GitHub Desktop.
A Python script that displays the current Org-mode clock status in Waybar (Sway/Wayland status bar). Shows the active task name and elapsed time, or "No active clock" when nothing is being tracked.
#!/usr/bin/env python3
import subprocess
import json
def get_current_clock():
try:
# Elisp to get current clock info with elapsed time
elisp_command = '''
(if (org-clock-is-active)
(format "%s [%s]"
(let ((heading org-clock-heading))
(if (> (length heading) 30)
(concat (substring heading 0 27) "...")
heading))
(org-duration-from-minutes
(floor (org-time-convert-to-integer
(time-subtract (current-time) org-clock-start-time))
60)))
"No active clock")
'''
# Run emacsclient to query running Emacs instance
result = subprocess.run(
["emacsclient", "-e", elisp_command],
capture_output=True,
text=True,
timeout=1
)
# Clean up the output
output = result.stdout.strip().replace('"', '')
# JSON format for waybar
return {
"text": output,
"class": "active" if output != "No active clock" else "inactive",
"tooltip": output
}
except Exception as e:
return {
"text": "Error",
"class": "error",
"tooltip": str(e)
}
if __name__ == "__main__":
print(json.dumps(get_current_clock()))
@jishnurajendran
Copy link
Author

Waybar Org-mode Clock Module

A Python script that displays the current Org-mode clock status in Waybar (Sway/Wayland status bar). Shows the active task name and elapsed time, or "No active clock" when nothing is being tracked.

Requires:

  • Running Emacs daemon
  • Waybar - emacsclient
  • org-mode

Usage:

  • Add to Waybar config as a custom module to monitor your Org-mode time tracking directly in your status bar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment