I’d like to develop a simple watcher for https://www.zettlr.com/, which seems based on chromium.
Currently, AW only logs the window title “Zettlr”, and similar to Chrome/Firefox I’d like to track the title of the active tab as well.
I’ve read the description on how to write a custom watcher, but coming from PHP I’m not sure what to do.
Can anyone help me how to run setup a test system (or test plugin) so I can develop/debug the code to see where I can access the value of the tab title from Zettlr?
I asked gemini to create a demo script about this, it came up with
import time
from datetime import datetime, timezone
import pygetwindow as gw
from aw_client import ActivityWatchClient
from aw_core.models import Event
# Configuration
CLIENT_NAME = "aw-watcher-zettlr"
BUCKET_ID = f"{CLIENT_NAME}_local"
POLL_TIME = 1.0 # Check every second
def get_zettlr_info():
"""
Finds the active Zettlr window and parses its title.
Zettlr titles usually look like: 'My Note.md - Zettlr'
"""
try:
active_win = gw.getActiveWindow()
if active_win and "Zettlr" in active_win.title:
title = active_win.title
# Strip the suffix to get the filename
filename = title.replace(" - Zettlr", "").strip()
return {"file": filename, "app": "Zettlr"}
except Exception:
pass
return None
def main():
# 1. Connect to ActivityWatch
client = ActivityWatchClient(CLIENT_NAME, testing=False)
# 2. Create the bucket (it won't overwrite if it exists)
client.create_bucket(BUCKET_ID, event_type="app.zettlr.activity")
print(f"Watcher started. Tracking Zettlr activity to bucket: {BUCKET_ID}")
while True:
try:
data = get_zettlr_info()
if data:
# 3. Create an event
# The 'heartbeat' function merges consecutive identical events
event = Event(timestamp=datetime.now(timezone.utc), data=data)
# 'pulsetime' is the max gap (in seconds) to merge events
client.heartbeat(BUCKET_ID, event, pulsetime=POLL_TIME + 1.0)
time.sleep(POLL_TIME)
except KeyboardInterrupt:
print("Watcher stopped.")
break
if __name__ == "__main__":
main()
I’d recommend using a LLMs for this. They can guide you through setting up python, installing the packages, testing and debugging. If you get stuck let me know I might be able to help.
I created an easy to install project repo for this, but it seems that Zettlr does not surface document information. The application title will always be Zettlr. If you want more info, you will need to submit an issue in the Zettlr repo to have an option to surface this in the application title. There is currently an issue to add an api to the software that might be useful for this, but it seems to be fairly old and stale. It might also be easier to just add the this info into the title rather than wait for the API and implement calls to the API in the watcher code.