Watches a folder for supported files, compresses them with high visual quality, and saves them to an output folder β automatically, silently, forever.
I wanted a lightweight local automation tool that could continuously compress files without relying on cloud services or manual processing.
Most existing tools were either:
- online only
- bloated
- subscription-based
- not automated
So I decided to build my own.
INPUT/ OUTPUT/
βββ report.pdf βββββββΊ βββ comp_report.pdf β compressed
βββ image.jpg βββββββΊ βββ comp_image.jpg β compressed
βββ photo.png βββββββΊ βββ comp_photo.png β compressed
βββ comp_old.pdf (skip) βββ ...
βββ notes.txt (ignore)
- Monitors INPUT continuously using OS-level file events (no polling loop)
- Processes existing supported files in INPUT on startup
- Waits for file transfers to finish before compressing
- Supports multiple formats:
- JPG / JPEG
- PNG
- WEBP
- Compresses PDFs with high visual quality optimisation
- Compresses images while preserving original format
- Renames output as
comp_<originalname> - Saves compressed files to OUTPUT, leaving originals untouched
- Ignores unsupported files and already-compressed files silently
- Logs all activity to
logs/watcher.log - Uses ~0% CPU while idle (fully event-driven)
- Video compression
- Drag-and-drop UI
- Compression presets
- EXE installer
- Batch processing
This project was designed to run fully autonomously in the background with minimal user interaction.
Current automation capabilities include:
- Silent background execution using
pythonw - Windows startup automation via
shell:startup - Optional Task Scheduler integration
- Standalone executable support using PyInstaller
- Continuous real-time folder monitoring
- Automatic file detection and processing
- Logging system for debugging and monitoring
- Lightweight idle performance (~0% CPU usage)
The system has been repeatedly tested across:
- system restarts
- startup execution
- silent background runs
- EXE-based deployment workflows
SmartCompress/
β
βββ watcher.py β Main program (monitoring + compression logic)
βββ config.py β YOUR settings (edit folder paths here)
βββ requirements.txt β Python package dependencies
β
βββ run.bat β Launch with a visible terminal window (easy debugging)
βββ run_silent.pyw β Launch silently in background (no window)
βββ stop.bat β Stop the background process
βββ startup.vbs β Drop in Windows Startup folder for autostart on boot
β
βββ build_exe.spec β Optional: build a standalone .exe with PyInstaller
β
βββ logs/
βββ watcher.log β All activity and errors are logged here
- Go to https://www.python.org/downloads/
- Click the big yellow "Download Python 3.x.x" button
- Run the installer
β οΈ Important: Check β "Add Python to PATH" at the bottom of the first screen- Click "Install Now"
To verify it worked, open Command Prompt (Win+R β type cmd β Enter) and run:
python --version
You should see something like Python 3.12.3.
Save the entire SmartCompress folder somewhere permanent, for example:
C:\Users\YourName\Documents\SmartCompress\
Open config.py in Notepad (right-click β Open With β Notepad).
Change these two lines to your actual folder paths:
FOLDER_A = r"C:\Users\YourName\Documents\INPUT" # watch this folder
FOLDER_B = r"C:\Users\YourName\Documents\OUTPUT" # save compressed files hereTips:
- Use
r"..."(note therbefore the quote) to avoid issues with backslashes - Both folders must exist before running (Folder B is auto-created if missing)
- You can use any folder paths, including network drives like
r"\\server\share\pdfs"
Optionally adjust compression quality (default 85 is excellent):
JPEG_QUALITY = 85 # 75 = smaller files, 92 = near-losslessDouble-click run.bat β it will automatically install all required packages
the first time you run it.
Or install manually via Command Prompt:
cd C:\Users\YourName\Documents\SmartCompress
pip install -r requirements.txt
This installs:
| Package | Purpose |
|---|---|
watchdog |
Efficient OS-level folder monitoring |
pypdf |
Pure-Python PDF manipulation |
Pillow |
Image recompression within PDFs |
Option A β With a terminal window (recommended for first use):
Double-click run.bat
You'll see live output like:
2024-01-15 10:30:00 [INFO] SmartCompress starting up
2024-01-15 10:30:00 [INFO] Watching : C:\Users\You\Documents\INPUT
2024-01-15 10:30:00 [INFO] Output : C:\Users\You\Documents\OUTPUT
2024-01-15 10:30:00 [INFO] β Detected: quarterly_report.pdf
2024-01-15 10:30:01 [INFO] β Compressed: 4.2 MB β 1.8 MB (57.1% smaller)
2024-01-15 10:30:01 [INFO] Watching for supported files... (press Ctrl+C to stop)
Option B β Silent background (no window):
Double-click run_silent.pyw
Nothing visible happens β the program runs quietly in the background.
Check logs/watcher.log to confirm it's working.
Recommended method: Windows Task Scheduler for silent startup automation.
startup.vbsis included as optional legacy support.
To start the compressor automatically every time you log into Windows:
-
Press
Win+R, typeshell:startup, press Enter β A folder opens (this is your Startup folder) -
Open
startup.vbsin Notepad and change this line:SCRIPT_PATH = "C:\Users\YourName\Documents\SmartCompress\run_silent.pyw"
to match where you saved the project.
-
Copy
startup.vbsinto the Startup folder that opened in step 1. -
Test it: Double-click
startup.vbsβ the watcher should start silently. Checklogs/watcher.logto confirm. -
On next login, it starts automatically. β
To remove autostart: Delete startup.vbs from the Startup folder.
To stop the background process: Double-click stop.bat
If you want to share this tool with someone who doesn't have Python installed, you can build a single self-contained executable.
pip install pyinstaller
cd C:\Users\YourName\Documents\SmartCompress
pyinstaller build_exe.spec
dist\watcher\watcher.exe
Share the entire dist\watcher\ folder. The recipient just needs to:
- Edit
config.pyinside the folder with their paths - Double-click
watcher.exe
No Python installation required on their machine. β
All activity is saved to logs/watcher.log.
Example log output:
2024-01-15 09:00:00 [INFO] ============================
2024-01-15 09:00:00 [INFO] PDF Auto-Compressor starting
2024-01-15 09:00:00 [INFO] Watching : C:\...\INPUT
2024-01-15 09:00:00 [INFO] β Detected: contract.pdf
2024-01-15 09:00:01 [INFO] β Compressed: contract.pdf 8.3 MB β 2.1 MB (74.7% smaller)
2024-01-15 09:05:12 [INFO] β Detected: scan.pdf
2024-01-15 09:05:13 [INFO] β Compressed: scan.pdf 12.0 MB β 3.4 MB (71.7% smaller)
The log file never grows unbounded β rotate it manually or let it grow (it's text, very compact).
| Problem | Solution |
|---|---|
python not found |
Re-install Python and check "Add to PATH" |
pip install fails |
Run Command Prompt as Administrator |
| File not being detected | Check Folder A path in config.py is correct |
| Output looks wrong | Raise JPEG_QUALITY in config.py to 92 |
| No size reduction | PDF may contain vector art only (no images to compress) β this is fine, the file is still losslessly optimised |
| Process won't stop | Open Task Manager β Details tab β find pythonw.exe β End Task |
The tool uses a two-stage approach for maximum quality-to-size ratio:
Stage 1 β Image recompression Each page's embedded images are extracted, decoded, re-encoded as JPEG at the configured quality level (default 85/100), and put back. Images are only replaced if the result is actually smaller. Vector graphics, text, and page structure are untouched.
Stage 2 β Lossless structural optimisation Duplicate PDF objects are merged, orphan objects are removed, and streams are compressed. This is always lossless and costs nothing in visual quality.
What's NOT changed:
- Text content
- Vector graphics / diagrams
- Page structure and layout
- Fonts
- Metadata (author, title, etc.)
- Original file (always kept)
| Package | Version | License | Why |
|---|---|---|---|
| watchdog | 4.0.1 | Apache 2.0 | OS-level folder monitoring |
| pypdf | 4.3.1 | BSD | PDF read/write, object deduplication |
| Pillow | 10.3.0 | HPND | JPEG image recompression |
All are permissively licensed and safe for personal and commercial use.
Built with Python 3.10+ β’ Tested on Windows 10/11