A Python CLI tool for automatically cleaning up old macOS screenshots
Project description
Screenshot Cleaner
A Python CLI tool for automatically cleaning up old macOS screenshots. Keep your Desktop tidy by automatically deleting screenshots older than a specified number of days.
Features
- ๐ macOS Native: Designed specifically for macOS screenshot patterns
- ๐ Smart Detection: Automatically finds screenshots by filename pattern
- ๐ก๏ธ Safe Operation: Preview mode and confirmation prompts prevent accidental deletion
- ๐ Rich Output: Beautiful tables and colorized console output
- ๐ Logging: Optional file logging for audit trails
- โก Fast: Efficiently scans directories with thousands of files
Installation
From PyPI (Recommended)
Install using pip:
pip install screenshot-cleaner
Or using uv:
uv tool install screenshot-cleaner
From Source
Install from the repository:
git clone <repository-url>
cd screenshot-cleaner
uv sync
Usage
Preview Mode
See which screenshots would be deleted without actually deleting them:
# Preview screenshots older than 7 days (default)
screenshot-cleaner preview
# Preview with custom age threshold
screenshot-cleaner preview --days=14
# Preview ALL screenshots (no age filter)
screenshot-cleaner preview --days=0
# Preview in a specific directory
screenshot-cleaner preview --path=/path/to/screenshots
# Save log to file
screenshot-cleaner preview --log-file=preview.log
Clean Mode
Delete old screenshots:
# Clean with confirmation prompt
screenshot-cleaner clean
# Clean without confirmation (use with caution!)
screenshot-cleaner clean --force
# Dry run (preview without deleting)
screenshot-cleaner clean --dry-run
# Custom age threshold
screenshot-cleaner clean --days=30
# Delete ALL screenshots (use with extreme caution!)
screenshot-cleaner clean --days=0 --force
# Custom directory
screenshot-cleaner clean --path=/path/to/screenshots
# With logging
screenshot-cleaner clean --force --log-file=cleanup.log
Command Reference
preview
Preview screenshots that would be deleted.
Arguments:
--path: Screenshot directory (default: ~/Desktop)--days: Age threshold in days (default: 7)--log-file: Optional log file path
clean
Delete old screenshots.
Arguments:
--path: Screenshot directory (default: ~/Desktop)--days: Age threshold in days (default: 7)--force: Skip confirmation prompt--dry-run: Preview only, don't delete--log-file: Optional log file path
macOS Automation
You can configure macOS to run Screenshot Cleaner automatically using LaunchAgents.
Setup Instructions
-
Install the tool globally:
uv tool install screenshot-cleaner
-
Find the installation path:
which screenshot-cleaner -
Create a plist file at
~/Library/LaunchAgents/com.screenshotcleaner.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.screenshotcleaner</string>
<key>ProgramArguments</key>
<array>
<string>/Users/YOUR_USERNAME/.local/bin/screenshot-cleaner</string>
<string>clean</string>
<string>--force</string>
<string>--days</string>
<string>0</string>
</array>
<!-- Run at every reboot -->
<key>RunAtLoad</key>
<true/>
<key>StandardOutPath</key>
<string>/tmp/screenshot-cleaner.log</string>
<key>StandardErrorPath</key>
<string>/tmp/screenshot-cleaner.error.log</string>
</dict>
</plist>
-
Update the path in
ProgramArgumentsto match your installation -
Load the LaunchAgent:
launchctl load ~/Library/LaunchAgents/com.screenshotcleaner.plist
-
Verify it's loaded:
launchctl list | grep screenshotcleaner
Scheduling Options
Run at startup:
<key>RunAtLoad</key>
<true/>
Run daily at 9 AM:
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>9</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
Run every 6 hours:
<key>StartInterval</key>
<integer>21600</integer>
Unload LaunchAgent
To stop automatic execution:
launchctl unload ~/Library/LaunchAgents/com.screenshotcleaner.plist
Development
Setup
# Clone the repository
git clone <repository-url>
cd screenshot-cleaner
# Install dependencies
uv sync
# Run tests
uv run pytest
# Run tests with coverage
uv run pytest --cov=screenshot_cleaner --cov-report=html
Project Structure
screenshot_cleaner/
โโโ __init__.py
โโโ cli.py # Fire CLI entry point
โโโ core/
โ โโโ __init__.py
โ โโโ scanner.py # File discovery and filtering
โ โโโ cleanup.py # Deletion operations
โ โโโ platform.py # OS detection
โโโ utils/
โโโ __init__.py
โโโ logging.py # Logging utilities
tests/
โโโ core/
โ โโโ test_platform.py
โ โโโ test_scanner.py
โ โโโ test_cleanup.py
โโโ utils/
โ โโโ test_logging.py
โโโ test_cli.py
Running Tests
# Run all tests
uv run pytest
# Run specific test file
uv run pytest tests/core/test_scanner.py
# Run with verbose output
uv run pytest -v
# Generate coverage report
uv run pytest --cov=screenshot_cleaner --cov-report=html
open htmlcov/index.html
Version Management
This project uses bump-my-version for automated semantic versioning.
Semantic Versioning:
MAJOR.MINOR.PATCHformat (e.g.,0.1.0)- MAJOR: Breaking changes
- MINOR: New features (backward compatible)
- PATCH: Bug fixes
Bumping Versions:
# Patch release (0.1.0 โ 0.1.1)
uv run bump-my-version bump patch
# Minor release (0.1.0 โ 0.2.0)
uv run bump-my-version bump minor
# Major release (0.1.0 โ 1.0.0)
uv run bump-my-version bump major
What happens when you bump:
- Version updated in
pyproject.toml - Version updated in
screenshot_cleaner/__init__.py - Git commit created automatically
- Git tag created (e.g.,
v0.2.0)
Before bumping:
- Ensure all changes are committed
- Run tests to verify everything works
- Update CHANGELOG.md with changes
Show current version:
uv run bump-my-version show current_version
Dry-run (preview changes):
uv run bump-my-version bump patch --dry-run --verbose
Release Workflow
Automated Release Script:
The easiest way to create a release:
# For bug fixes (0.1.0 โ 0.1.1)
./scripts/release.sh patch
# For new features (0.1.0 โ 0.2.0)
./scripts/release.sh minor
# For breaking changes (0.1.0 โ 1.0.0)
./scripts/release.sh major
The script will:
- Run tests and verify coverage
- Show preview of version bump
- Ask for confirmation
- Bump version and create git tag
- Push changes and tags to remote
Manual Release Process:
- Make your changes and commit them
- Run tests to ensure everything works:
uv run pytest --cov=screenshot_cleaner
- Update CHANGELOG.md with your changes
- Bump the version:
# For bug fixes uv run bump-my-version bump patch # For new features uv run bump-my-version bump minor # For breaking changes uv run bump-my-version bump major
- Push changes and tags:
git push git push --tags
Contributing
Contributions are welcome! Please read our Contributing Guide for details on:
- Development setup
- Code standards
- Testing guidelines
- Version management
- Pull request process
- Release workflow
Quick Guidelines
- Write tests for new features
- Maintain test coverage above 90%
- Follow existing code style
- Update documentation as needed
- Add type hints to all functions
- Use semantic versioning for releases
- Update CHANGELOG.md with your changes
See CONTRIBUTING.md for complete details.
Troubleshooting
"This tool only runs on macOS"
Screenshot Cleaner is designed specifically for macOS and will not run on other operating systems.
No screenshots found
- Verify you're looking in the correct directory (default is ~/Desktop)
- Check that your screenshots match the expected patterns:
- "Screen Shot *.png"
- "Screenshot *.png"
- Try using
--pathto specify a different directory
Permission errors
Ensure you have read/write permissions for the target directory.
License
MIT License - see LICENSE file for details.
Publishing
For maintainers: See PUBLISHING.md for instructions on publishing to PyPI.
Quick release:
./scripts/release.sh patch # Creates tag and triggers PyPI publish
Acknowledgments
Built with:
- Python Fire - CLI framework
- Rich - Terminal formatting
- uv - Python package manager
Published to PyPI
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file screenshot_cleaner-1.0.0.tar.gz.
File metadata
- Download URL: screenshot_cleaner-1.0.0.tar.gz
- Upload date:
- Size: 70.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc6d91db69becd2ffc477030c83b9c379abf46534a032b68a636f7e419efbf90
|
|
| MD5 |
97823d471e1a256b547108c1facb2a83
|
|
| BLAKE2b-256 |
41e4ea3a282245e32f454d129d3a381103d5f19753e2dfbdf8d7b0f106faccb5
|
Provenance
The following attestation bundles were made for screenshot_cleaner-1.0.0.tar.gz:
Publisher:
main.yml on damienjburks/screenshot-cleaner
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
screenshot_cleaner-1.0.0.tar.gz -
Subject digest:
dc6d91db69becd2ffc477030c83b9c379abf46534a032b68a636f7e419efbf90 - Sigstore transparency entry: 708304220
- Sigstore integration time:
-
Permalink:
damienjburks/screenshot-cleaner@c761a2de715beea17fd6e0825fb677135b5ae4b9 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/damienjburks
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main.yml@c761a2de715beea17fd6e0825fb677135b5ae4b9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file screenshot_cleaner-1.0.0-py3-none-any.whl.
File metadata
- Download URL: screenshot_cleaner-1.0.0-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
504d0f5bb50be23b24c0887ebd17fa7e85702c377c5037da31cdd37bbc8e4399
|
|
| MD5 |
e5050e2462398b4b09397b6aed74a596
|
|
| BLAKE2b-256 |
c1388a20e9e77af8ecbdcb0115dd5ba6cbef758cf3571e67b8257bdca2ceef57
|
Provenance
The following attestation bundles were made for screenshot_cleaner-1.0.0-py3-none-any.whl:
Publisher:
main.yml on damienjburks/screenshot-cleaner
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
screenshot_cleaner-1.0.0-py3-none-any.whl -
Subject digest:
504d0f5bb50be23b24c0887ebd17fa7e85702c377c5037da31cdd37bbc8e4399 - Sigstore transparency entry: 708304221
- Sigstore integration time:
-
Permalink:
damienjburks/screenshot-cleaner@c761a2de715beea17fd6e0825fb677135b5ae4b9 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/damienjburks
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main.yml@c761a2de715beea17fd6e0825fb677135b5ae4b9 -
Trigger Event:
push
-
Statement type: