Skip to content

Use clearxx to Help you Build and Run a Script on your Computer

Automating repetitive work

Nina Falk handles bookkeeping for a small architecture firm. Every month, supplier invoices land in her inbox as PDFs with names like scan001.pdf, IMG_4471.pdf, and invoice_final_v2.pdf. Before she can close the books, she opens each one, works out which supplier it belongs to, renames it, and drags it into the right folder. It is the same task every month, it never needs judgment once she knows who the supplier is, and it eats the better part of an afternoon.

This case follows Nina through the whole process — deciding this should be a script, agreeing on a structure with the clearxx Assistant, having Cline build and test it, having the Assistant check it, and running it for real locally on your computer.

A Simple Mental Model

Step What happened Who did it
Decide Confirmed this should be a local script Nina, with the clearxx Assistant
Structure Agreed on an Inbox and per-vendor folders Nina, with the clearxx Assistant
Naming Agreed on Invoice_[Vendor]_[Date].pdf Nina, with the clearxx Assistant
Build Wrote and tested the script against sample invoices Cline
Check Reviewed the finished script against the plan The clearxx Assistant
Install Set up Python once Nina
Run Runs it herself, once a month Nina

Watch It Work: Before Automation

On the first Monday of every month, Nina opens a folder of forty or fifty PDFs with no consistent names at all. She opens each one to see which supplier it is from, renames it by hand, and moves it into that supplier's folder. A renamed file that ends up in the wrong folder is easy to miss until the books do not add up weeks later. The task itself never changes — only the number of files does.

Watch It Work: Setting It Up

Deciding This Should Be a Script

Nina: I do the exact same invoice sorting every month — same steps, same folders, just different files. Should this be a script?

clearxx Assistant: Yes. This is a clean fit: identical steps every time, no judgment involved once you know who the supplier is, and frequent enough that it is worth setting up once.

Agreeing on a Folder Structure

Nina: Right now everything just lands in one Downloads folder. Help me design something a script could actually rely on.

clearxx Assistant: Here is a starting point:

Invoices/
  Inbox/
  Vendors/
    [VendorName]/

New PDFs land in Inbox, and the script moves each one into the matching folder under Vendors. One question before this is final: should vendor folders be named after the supplier exactly as it appears on the invoice, or a short internal code, in case a supplier is ever listed under two slightly different names?

Nina: Exact supplier name is fine — we only have about fifteen regular vendors.

Agreeing on a Naming Convention

Weak (a script cannot rely on this) Reliable (a script can parse this every time)
scan001.pdf Invoice_AcmeSupplies_2025-03-14.pdf
IMG_4471.pdf Invoice_NordicTimberCo_2025-03-02.pdf
invoice_final_v2.pdf Invoice_BrightSteelLtd_2025-03-19.pdf

Nina: From now on, every invoice gets renamed to Invoice_[Vendor]_[Date].pdf, date as YYYY-MM-DD, before it goes into the Inbox. Does that work for a script?

clearxx Assistant: Yes, with one addition: vendor names should have no spaces — use AcmeSupplies, not Acme Supplies — so the script can split the filename apart reliably at each underscore.

Cline Builds It, the Assistant Checks It

This script only needs to run once a month, but a mistake here means a real invoice filed under the wrong supplier — worth having it proven correct before it ever touches a real file.

Nina: Can you write me a prompt for Cline to build this?

clearxx Assistant: Here is a prompt for Cline:

"Write a Python script that reads every PDF in an Inbox folder and moves it into the matching folder under Vendors, based on the filename pattern Invoice_[Vendor]_[Date].pdf. Create the vendor folder if it does not exist yet. Any file that does not match the pattern should be skipped and listed in a short report, never guessed at. Test it against a handful of sample files with different vendors and dates before confirming it works."

Paste this into Cline in the Agent & Build Workspace. Nina will need a few sample invoices for Cline to test against — blank test PDFs with the right filenames work fine, the content does not matter for this. Once Cline confirms it works, bring the finished script back here and I will check it against what we agreed.

Nina creates five empty test PDFs with names like Invoice_AcmeSupplies_2025-01-10.pdf and one deliberately broken one, scan_final.pdf, and hands them to Cline along with the prompt. Cline writes the script, runs it against the test files inside the Agent & Build Workspace, confirms the five valid files moved into the correct vendor folders, and confirms the broken filename was skipped and listed rather than guessed at.

Nina: Here is the script Cline built and tested. Does it match what we agreed on?

clearxx Assistant: Mostly, with one thing worth fixing: right now, if two invoices from the same vendor share the same date, the second one silently overwrites the first instead of being renamed or flagged. Ask Cline to add a check for that before you install anything.

Nina sends that one line back to Cline, gets an updated version, and this time the check passes cleanly.

Installing Python and Saving the Script

Nina has not used Python before, so she follows the step-by-step Windows instructions from the local-tools setup guide: open PowerShell, install Python with winget, install the one package the script needs, and save the finished script into the Invoices folder she and the Assistant designed together.

Running It

Once a month is not often enough to bother scheduling. Nina simply opens PowerShell, navigates to the folder, and runs the script by hand on the first Monday of the month, the same way she tested it.

A Few Months Later — Something Breaks, and Gets Fixed

In June, a new supplier sends their first invoice, formatted differently from everyone else. The script's safeguard does exactly what it was built to do: it skips the file and lists it in the report, rather than filing it somewhere wrong.

Nina: The report flagged one file this month: RE-2025-0603-BrightSteelLtd.pdf. What happened?

clearxx Assistant: That filename does not match the pattern we agreed on — it looks like this new supplier uses their own invoice numbering format. Easiest fix: rename it to match your convention before dropping it in the Inbox, the same as any other invoice. If this supplier sends invoices monthly going forward, it might be worth asking Cline to recognize their format specifically — but for one invoice, a manual rename is faster than changing the script.

The Finished Script

import re
import shutil
from pathlib import Path

INBOX = Path("Invoices/Inbox")
VENDORS = Path("Invoices/Vendors")
PATTERN = re.compile(r"^Invoice_([A-Za-z0-9]+)_(\d{4}-\d{2}-\d{2})\.pdf$")

skipped = []

for file in INBOX.glob("*.pdf"):
    match = PATTERN.match(file.name)
    if not match:
        skipped.append(file.name)
        continue

    vendor, date = match.groups()
    vendor_folder = VENDORS / vendor
    vendor_folder.mkdir(parents=True, exist_ok=True)

    destination = vendor_folder / file.name
    if destination.exists():
        skipped.append(f"{file.name} (duplicate — not moved)")
        continue

    shutil.move(str(file), str(destination))

if skipped:
    print("Skipped — check these manually:")
    for name in skipped:
        print(f"  {name}")
else:
    print("All invoices filed successfully.")

This is short enough to read end to end, and every safeguard in it traces back to a specific decision made earlier in the case: the pattern check comes from Step 3, the duplicate check comes from the Assistant's review in Step 4, and the skip-and-report behavior, rather than a guess, comes from the original prompt to Cline.

When to Reach for This

Good fit Why
"I do the exact same file-sorting task every month, and it always takes an afternoon." Identical steps, no judgment involved — the core case for a script.
"A mistake here is costly enough that I want it tested before it touches real files." This is exactly why Cline built and tested it first, and the Assistant checked it afterward.

When Not To

Too much Why
"Help me decide which of these invoices look wrong or fraudulent." That needs judgment about content, not filenames — this belongs in Chat or Cline directly, not a script.
"I only get three invoices a year." Not worth the setup time. Just sort them by hand.

Tips From Actually Using It

  1. Create test files before asking Cline to build anything. A handful of blank PDFs with the right filenames are enough — Cline needs something real to test against, not just a description.
  2. Always ask for a skip-and-report safeguard, not a guess. A script that silently guesses wrong is far worse than one that stops and asks.
  3. Bring the finished script back to the Assistant, even after Cline confirms it works. Cline verifying it runs and the Assistant confirming it matches your actual plan catch two different kinds of mistakes.
  4. Do not automate the schedule until the manual runs feel routine. Nina ran this by hand for two months before ever considering Task Scheduler — there was no need to add that complexity for something this infrequent.

FAQ

Did Nina need to know Python to do this? No. She never wrote a line of it. Cline wrote it, the Assistant checked it, and Nina only had to run the two setup commands from the local-tools guide.

What happens if a vendor is misspelled in one invoice? The script treats it as a different vendor and creates a new folder for it — this is exactly the kind of thing worth catching in the monthly skip report, since a misspelled vendor will not match any existing folder name.