4.9 KiB
Brother Scanner Auto-Workflow
Automated scanning workflow for Brother DS mobile scanners with LLM-powered document naming.
Features
- 🔍 Auto-detect - Automatically detects when you place a document in the scanner
- 📄 Auto-scan - Starts scanning without manual intervention
- 🧠 Smart naming - Uses LLM to generate meaningful titles
- 💾 Local storage - Saves to configured local folder
- 📊 Scan logging - Tracks all scans in JSON log
Prerequisites
Hardware
- Brother DS-640 scanner (or compatible Brother mobile scanner)
Software
- Python 3.9+
- Brother scanner drivers and CLI tools (
brscan-skeyorbrscan4) - LLM API (OpenAI or OpenAI-compatible like Ollama)
Installation
-
Clone or navigate to the project directory:
cd scanner-workflow -
Install Python dependencies:
pip install -r requirements.txt -
Configure environment variables:
cp .env.example .env # Edit .env and add your API key -
Configure scanner settings (optional):
# Edit config.yml to set scan directory and brother command # For DS-640, try: brother_cmd: "brscan-skey -s"
Usage
Basic Auto-Scan (Continuous Mode)
Run the scanner in auto-detect mode. It will wait for you to place a document and automatically scan it:
python scanner-auto.py
The script will:
- Wait for you to place a document in the scanner
- Auto-detect when the document is ready
- Start scanning automatically
- Generate a meaningful title using LLM
- Save as
{title} - {timestamp}.pdf
Limit Number of Scans
Scan a maximum of 10 documents and then stop:
python scanner-auto.py --max-scans 10
Test Scanner Detection
Check if the scanner is detected without actually scanning:
python scanner-auto.py --test
Configuration
config.yml
# Directory where scanned PDFs will be saved
scan_dir: "scans"
# Brother scanner command
brother_cmd: "brscan-skey -s"
# LLM API configuration
api_url: "http://localhost:11434/v1/chat/completions"
model: "llama3"
.env
# LLM API Key (optional for local LLMs like Ollama)
API_KEY=
File Structure
scanner-workflow/
├── scanner-auto.py # Main script
├── config.yml # Configuration
├── .env.example # Environment template
├── requirements.txt # Python dependencies
├── README.md # This file
├── .env # Your API key (create from .env.example)
├── scans/ # Output directory (auto-created)
│ ├── scan_log.json # Scan history
│ └── *.pdf # Scanned documents
└── tests/ # (optional) Test scripts
LLM Integration
Using OpenAI
Set your API key in .env:
API_KEY=sk-your-openai-api-key
Update config.yml:
api_url: "https://api.openai.com/v1/chat/completions"
model: "gpt-3.5-turbo"
Using Ollama (Local)
No API key needed! Just run Ollama locally and update config.yml:
api_url: "http://localhost:11434/v1/chat/completions"
model: "llama3"
Install Ollama:
# macOS
brew install ollama
# Linux
curl -fsSL https://ollama.com/install.sh | sh
# Then pull the model
ollama pull llama3
Troubleshooting
Scanner not detected
-
Check if Brother scanner tools are installed:
brscan-skey --version -
Try different
brother_cmdinconfig.yml:brother_cmd: "brscan4 -s" -
Test detection:
python scanner-auto.py --test
LLM not working
- Verify API key in
.env - Check API URL in
config.yml - Test API connectivity:
curl -X POST $api_url \ -H "Authorization: Bearer $API_KEY" \ -H "Content-Type: application/json" \ -d '{"model":"'$model'","messages":[{"role":"user","content":"Hello"}]}'
Permission errors
Make sure the script can write to the scan directory:
chmod +x scanner-auto.py
Example Output
============================================================
🤖 Brother Scanner - Auto-Detect Mode
============================================================
📁 Scan directory: scans
🔄 Brother command: brscan-skey -s
🧠 LLM API: http://localhost:11434/v1/chat/completions
============================================================
[14:30:15] Waiting for document...
✓ Document detected by scanner
→ Starting scan: brscan-skey -s -f scans/scan_20260214_143015.pdf
✓ Scan completed: scan_20260214_143015.pdf (245678 bytes)
→ Generating title with LLM...
✓ LLM title: Invoice from Acme Corp
✓ Saved as: Invoice from Acme Corp - 20260214_143015.pdf
License
MIT License - Feel free to use and modify as needed.
Contributing
Suggestions and improvements welcome!