Cloning Windows Recall in 30 Lines of Bash
June 6, 2024
This is mostly a demonstration of what Windows Recall actually seems to do under the hood, and is not meant to be seriously used.
Here’s the code, I have more to say after:
#!/usr/bin/env bash
if [ "$1" == "--daemon" ]; then
MD5LAST=""
while true; do
# Use the current date and time for the screenshot filename
FILE=~/recall/$(date +"%Y/%m/%d/%Y-%m-%d-%H:%M:%S")
mkdir -p $(dirname $FILE)
grim $FILE.png # Take a screenshot
# If the screenshot is the same as the last one, disregard it
MD5=$(md5sum $FILE.png | cut -d ' ' -f 1)
if [ "$MD5" == "$MD5LAST" ]; then
rm $FILE.png
sleep 5
continue
fi
MD5LAST=$MD5
# Run tesseract on the file to extract text from the image
# It always appends .txt to the filename, so the final name is $FILE.ocr.txt
tesseract $FILE.png $FILE.ocr > /dev/null 2>&1 &
sleep 5
done
exit 0
fi
# The arguments are assumed to be a ripgrep search query
FILES=$(rg --files-with-matches $@ ~/recall)
# Replace the filename extensions, which should be .ocr.txt, with .png
FILES=${FILES//.ocr.txt/.png}
mcomix $FILES
When called with --daemon
it will handle the screenshotting/OCR analysis, and when called with anything else it is interpreted as a ripgrep search.
Note this has quite a few dependencies, including Wayland since it is using grim for screenshotting. I would package it up using A Portable Nix-shell Shebang if I wanted to distribute it.
Why? Link to heading
I admit that I actually like the idea of having Recall available, I just want it to be OSS.
I’ve been thinking about writing my own version of Recall that could run cross platform, sync between devices, and that I could have full control over outside the whims of Microsoft.
I know that rem and xrem exist, but I would prefer to write my own greenfield project, and I struggled to get the xrem
GUI to work anyways.
I would also want to take the project in a slightly different direction.
The sheer amount of information that this tool would ingest would make it a good starting point as a centralized “Search Everything I’ve Used” tool, which the other projects don’t seem to be doing, and I’m tempted to build. For example, giving direct access to index your email/chat/photos/directories/cmd history/etc would allow the tool to also search through every other organized piece of data, and place the screenshots into the right context.
Instead of starting a full blown Rust project like I usually do (see pokem, chaz, cmprss, etc) I wanted to experiment with the tech a bit by writing a simple script to outline what the basic functionality of this thing actually is.
So one short coding session later here we have it.
Of course this script is barely usable, but it will absolutely work for watching everything that appears on your screen and searching for text that appears.