Last active
October 27, 2024 13:39
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
Usage: