Taking screenshots?

Hi,

Quick question: does ActivityWatch allow taking of periodic screenshots (every three minutes, for example), like TimeDoctor does?
Thanks!

Merc.

6 Likes

It currently does not, but it should be easy to write a script that does so yourself :slight_smile:

Having screenshots is extremely helpful when attempting to audit your time. It can also be helpful in recreating work after a system crash. If you find something like Activitywatch I would be interested in looking at it.

1 Like

I’ve messed around with this in the past. My solution is at https://github.com/kovasap/auto-screenshooter. If you want activitywatch to manage it, you could probably register it as a watcher somehow. I’m not sure about getting the image data into the AW UI though.

1 Like

Hi. I registered here to join this topic.
Currently im testing AW with ManicTime side by side. And only thing which interests me are timelines. MT’s big advantage is that it makes screenshots by itself, and adds them to the timelines view. So beside of seeing the apps which were used you can also see what exacly did you do in those apps. VERY usefull if you want to know more precisely which part of code did you edit or what exactly did you do on some site.
I know that you can do screenshots wit some script, but as you see below, screenshots combined with timelines are much more comfortable in use than comparing separately timelines and your folder with thousand of files.
I dont know about the others but for me its a killer feature which probably will convince me to pay this 67$ for MT than AW for freee.

2 Likes

I would like to see Activity watch allow taking of periodic screenshots. Even better, only take periodic screenshots for certain categories of activities or specific applications.

2 Likes

New to ActivityWatch but agree this would be a really great feature. Here is what I have started using and perhaps this can be added as a tab like the stopwatch feature. The user could then input their own preferences for storage folder, check interval and folder to store images. It would also be great if on the timeline hovering over a block would pull up a thumbnail but I think that might be beyond me.

import requests
import pyautogui
import time
import os
import datetime

AW_HOST = "http://localhost:5600"
AW_BUCKET = "aw-watcher-window_HOSTNAME"  # Replace HOSTNAME with your hostname
CHECK_INTERVAL = 5  # seconds
DAYS = 5
SCREENSHOT_FOLDER = r"<FOLDER TO SAVE PHOTOS>"

def get_active_window():
    try:
        response = requests.get(f"{AW_HOST}/api/0/buckets/{AW_BUCKET}/events?limit=1")
        response.raise_for_status()
        data = response.json()
        if data:
            return data[0]['data']['app'], data[0]['data']['title']
        return None, None
    except requests.RequestException:
        print("Error querying ActivityWatch. Is it running?")
        return None, None

def capture_screenshot(filename):
    pyautogui.screenshot(filename)

def remove_old_screenshots():
    now = datetime.datetime.now()
    for filename in os.listdir(SCREENSHOT_FOLDER):
        if filename.startswith("screenshot_") and filename.endswith(".png"):
            file_path = os.path.join(SCREENSHOT_FOLDER, filename)
            creation_time = datetime.datetime.fromtimestamp(os.path.getctime(file_path))
            if (now - creation_time).days > DAYS:
                os.remove(file_path)
                print(f"Deleted old screenshot: {filename}")

def main():
    last_app, last_title = None, None
    while True:
        app, title = get_active_window()
        if app and title and (app != last_app or title != last_title):
            timestamp = time.strftime("%Y%m%d-%H%M%S")
            screenshot_filename = os.path.join(SCREENSHOT_FOLDER, f"screenshot_{timestamp}.png")
            capture_screenshot(screenshot_filename)
            print(f"Captured screenshot for {title} saved as {screenshot_filename}")
            last_app, last_title = app, title

        # Check and remove old screenshots
        remove_old_screenshots()

        time.sleep(CHECK_INTERVAL)

if __name__ == "__main__":
    main()

How to Use:

  1. Prerequisites:
  • Ensure you have ActivityWatch running on your computer.
  • Install the required Python libraries: requests and pyautogui.
  1. Configuration:
  • Replace <FOLDER TO SAVE PHOTOS> in the SCREENSHOT_FOLDER variable with the path to the directory where you want to save the screenshots.
  • Replace HOSTNAME in the AW_BUCKET variable with your computer’s hostname.
  1. Run the Script:
  • Execute the script. It will start monitoring the active window and capture screenshots accordingly.

What It Does:

  • Active Window Monitoring: The script continuously checks the currently active window using ActivityWatch’s API.
  • Screenshot Capturing: Whenever the active window changes (e.g., you switch from a browser to a word processor), the script captures a screenshot and saves it to the specified folder.
  • Old Screenshot Removal: To avoid filling up your storage, the script automatically deletes screenshots older than a specified number of days (default is 5 days).

James

2 Likes

FYI: I have posted a suggestion / mockup in
Screenshots Watcher: Are custom Timeline visualations possible? - Projects - ActivityWatch Forum

I have written a simple screenshot grabber for KDE. It may help you till Activitywatch add this feature to at least have screenshots on Linux.
Maybe it is better!