β οΈ WARNING: UNTESTED SOFTWARE These tools have not yet been fully tested in production. Created to help manage iMessage storage, but not validated on all systems. If you found this repository randomly, please do not use until this notice is removed. Use at your own risk.
A suite of safe tools for cleaning up iMessage storage on macOS by handling duplicate images and videos that are already stored in your Photos library.
This tool is designed for a very specific situation:
β You should use this if:
- Your Mac is critically low on storage (5-20 GB free or less)
- System Settings shows Messages using 50-150+ GB of space
- You have thousands of images/videos shared via iMessage (especially baby photos, family videos)
- Many of these images/videos are already saved in your Photos library
- You're paying for storage twice (once in Messages, once in Photos)
- You can't afford to create duplicate copies during cleanup (no extra 50 GB available)
- You need to safely verify that items are in Photos before deleting from Messages
β You should NOT use this if:
- You have plenty of free disk space (50+ GB free) - just use general Mac cleaners
- Messages only uses 10-20 GB - not worth the effort
- You don't use Photos.app to organize media
- You want a one-click automated solution - this requires human verification
- Your Messages storage is mostly documents/PDFs, not photos/videos
The Niche: This tool was built for parents with young kids who share tons of photos/videos via iMessage family chats, where the disk is nearly full and every gigabyte matters. It uses batch processing to avoid disk space exhaustion during cleanup.
These tools help free up storage space (potentially 40-60 GB!) on your Mac by:
- Bulk importing images to Photos in batches (prevents disk from filling up)
- Smart video cleanup with hash-based verification to prove videos are already in Photos
- Nothing is permanently deleted - everything moved to review folders first
- Zero additional disk space required - moves files instead of copying them
Designed with multiple safety layers to protect precious family photos and videos, and specifically handles the constraint of having very little free disk space.
iMessage stores ALL attachments locally forever. Over time, this can use 100+ GB of storage, even though most of these images/videos are also in your Photos library. You're paying twice - once in Messages, once in Photos.
The challenge: When your disk is nearly full (6-10 GB free), traditional cleanup tools fail because they try to create duplicate copies during processing, which fills up your disk and crashes. This tool processes in small batches (500 images at a time) to keep disk usage minimal.
assess_all_imessage_files.py - Understand what's taking up space
- Analyzes ALL file types (videos, images, documents, audio)
- Shows storage breakdown by category
- Identifies top 30 largest files
- Recommends cleanup strategy
- Run this first to understand your situation!
bulk_image_importer.py - Handle thousands of images quickly (30-40 GB potential savings)
- Batch processing - processes 500 images at a time to avoid filling disk
- Each batch: Import to Photos β Move from Messages β Repeat
- Keeps extra disk usage to only ~1-2 GB (instead of 40+ GB)
- Critical for low-storage situations (6-20 GB free)
- Automatically skips corrupted files and burst photos (no dialogs)
- Photos detects duplicates automatically - merge them afterward
- Time: 10-15 minutes for ~25,000 images
smart_video_cleaner.py - Handle videos with verification (10-30 GB potential savings)
- Hash-based verification - proves video exists in Photos
- Interactive GUI to review each video
- Start with large videos (β₯100MB) for quick wins
- Shows Photos match status for each video
- You approve each decision
- Time: 20-40 minutes for 40 largest videos
- No immediate deletion - Files are moved to review folders, never permanently deleted by the script
- No disk space duplication - Files are moved (not copied), requiring zero additional disk space
- Review folders are your backup - Files remain in review folders until you manually delete them
- Human review - You manually approve every single video
- Import verification - Checks that Photos import succeeded before moving files
- Detailed logging - Complete audit trail of all actions
- Resume capability - Can pause and continue later
- Conservative matching - Only processes videos you explicitly approve
- Easy undo - Just move files back from review folders if needed
- macOS (tested on macOS 10.15+)
- Python 3 (built into macOS)
- Minimum 5-6 GB free disk space (for batch processing buffer)
- iMessage attachments stored locally
- Photos app with local library
- Pillow library for image validation:
pip3 install Pillow
# Verify Python 3 is available
python3 --version
# Install Pillow for image validation
pip3 install PillowYou should see Python version 3.9.6 or higher.
Before running either script, you need to grant Terminal (or your terminal app) "Full Disk Access" permission. macOS blocks access to the Messages folder for security.
- Open System Settings (or System Preferences on older macOS)
- Go to Privacy & Security β Full Disk Access
- Click the lock icon π at the bottom and authenticate
- Click the + button
- Navigate to
/Applications/Utilities/ - Select Terminal and click Open
- Restart Terminal completely (Cmd+Q then reopen)
- Run the script again
- If using iTerm2, VS Code terminal, or another terminal app, add that app instead
- The scripts will detect permission errors and show these instructions if needed
- This is safe - it only allows Terminal to read protected folders
Before doing anything else, run the comprehensive assessment to understand what's ACTUALLY taking up space:
cd /Users/matte/MessageClean
python3 assess_all_imessage_files.pyThis will show you:
- All file types (videos, images, documents, audio, etc.)
- Storage by category - which type uses the most space?
- Top 30 largest files - quick wins for manual cleanup
- Recommended strategy based on what it finds
- Size distribution across all files
This script is read-only and completely safe - it doesn't modify anything.
System Settings might report "126 GB for Messages", but you need to know:
- Is it videos? Images? PDFs? Audio files?
- Are there a few huge files or thousands of small ones?
- What cleanup strategy makes sense?
STORAGE BY CATEGORY
----------------------------------------------------------------------
Video : 7,054 files | 47.8 GB (38%)
Image : 15,230 files | 52.1 GB (41%)
Document : 145 files | 8.2 GB (7%)
Audio : 892 files | 3.1 GB (2%)
TOP 30 LARGEST FILES
----------------------------------------------------------------------
1. 146.2 MB - MOV_4445.MOV (Video)
2. 98.5 MB - vacation_video.mp4 (Video)
3. 45.2 MB - presentation.pdf (Document)
...
RECOMMENDATIONS
----------------------------------------------------------------------
Quick wins - manually review top 30 largest files
- Top 30 files = 3.2 GB
- Reviewing just 30 files could free up significant space
Run this first to understand your situation before deciding on a cleanup strategy!
cd MessageClean
python3 assess_all_imessage_files.pyThis shows you:
- What's taking up space (images? videos?)
- How much you could potentially save
- Which cleanup approach makes sense
Purpose: Handle 25,000+ images (30-40 GB potential savings)
python3 bulk_image_importer.pyWhat happens:
- Shows summary of images found
- Asks for confirmation
- Processes in batches of 500 images (~850 MB at a time):
- Import batch to Photos
- Immediately move batch from Messages
- Repeat for next batch
- This prevents disk from filling up!
- Automatically skips corrupted files and burst photos
- Takes 10-15 minutes for ~25,000 images
- Images moved to
~/Desktop/iMessage_Images_REVIEW/ - Creates log:
~/Desktop/iMessage_Image_Import_Log.txt
After it completes:
- Open Photos - verify images are there
- Merge duplicate photos (IMPORTANT - takes ~5 minutes):
- In Photos, click "Albums" in sidebar
- Scroll to "Utilities" section
- Click "Duplicates" album
- Click "Merge" for each duplicate set (or "Merge All")
- Check review folder - spot check a few images
- When satisfied, manually delete review folder:
rm -rf ~/Desktop/iMessage_Images_REVIEW
Purpose: Handle videos with verification (start with largest for quick wins)
Start with videos β₯100MB (recommended):
python3 smart_video_cleaner.py --min-size=100What happens:
- Scans for videos β₯100MB (typically 30-40 videos)
- Calculates file hashes
- Checks if each video exists in Photos (by size + filename)
- Opens interactive GUI showing each video:
- Video info (name, size, date)
- Photos match status: "β FOUND IN PHOTOS" or "β NOT FOUND"
- Three buttons:
- "Already in Photos - Safe to Remove" (if matched)
- "Import to Photos First, Then Remove" (if not matched)
- "Keep in Messages" (skip)
- You review and decide for each video
- Moves videos to
~/Desktop/iMessage_Videos_REVIEW/ - Creates log:
~/Desktop/iMessage_Video_Cleanup_Log.txt
After reviewing all videos:
- Open Photos - verify videos are there
- Check review folders:
already_in_photos/- Videos that were matchednewly_imported/- Videos that were just imported
- When satisfied, manually delete review folder:
rm -rf ~/Desktop/iMessage_Videos_REVIEW
Optional: Process more videos:
# Videos β₯50MB (typically 130-170 videos, more time investment)
python3 smart_video_cleaner.py --min-size=50
# Videos β₯10MB (1000+ videos, only if you need maximum cleanup)
python3 smart_video_cleaner.py --min-size=10After Phase 1 and Phase 2, run the assessment again to see your progress:
python3 assess_all_imessage_files.pyThis will show you:
- How much space you've freed up
- Whether you've hit your storage goal
- If you need to process more videos (e.g., run Phase 2 with
--min-size=50)
Based on real-world data:
Phase 1 (Images): 30-42 GB freed
- Depends on how many images are duplicates vs. unique to Messages
Phase 2 (Videos β₯100MB): 3-5 GB freed
- 30-40 largest videos
Phase 2 (Videos β₯50MB): 10-13 GB freed
- 130-170 videos
Total: 40-60 GB potential savings
| File/Folder | Purpose |
|---|---|
~/Desktop/iMessage_Images_REVIEW/ |
Images moved from Messages (delete when satisfied) |
~/Desktop/iMessage_Videos_REVIEW/ |
Videos moved from Messages (delete when satisfied) |
~/Desktop/iMessage_Image_Import_Log.txt |
Detailed log of image import |
~/Desktop/iMessage_Video_Cleanup_Log.txt |
Detailed log of video cleanup |
~/Desktop/iMessage_Video_Decisions.json |
Your decisions (can resume if interrupted) |
~/Desktop/iMessage_Video_Inventory.csv |
Assessment data |
Both tools support resuming:
Image Importer: Just run it again - it will skip already-imported images
Video Cleaner: Run the same command - it loads your previous decisions from the JSON file and continues where you left off
Before permanently deleting review folders:
-
Open Photos app
- Browse recent imports
- Spot-check videos are actually there
- Check a few images are present
-
Check review folders on Desktop
iMessage_Images_REVIEW/- Spot-check a few imagesiMessage_Videos_REVIEW/- Spot-check a few videos
-
Review the logs
iMessage_Image_Import_Log.txt- See what was importediMessage_Video_Cleanup_Log.txt- See what was processed
-
When satisfied everything is safe in Photos:
# Delete image review folder rm -rf ~/Desktop/iMessage_Images_REVIEW # Delete video review folder rm -rf ~/Desktop/iMessage_Videos_REVIEW
Don't rush this step! These are precious memories. Take your time verifying.
Make sure your Photos library is at the default location:
~/Pictures/Photos Library.photoslibrary
If it's elsewhere, you'll need to update the PHOTOS_LIBRARY variable in the script.
If you see PermissionError: [Errno 1] Operation not permitted, this means Terminal doesn't have access to the Messages folder.
Solution: Grant Terminal "Full Disk Access" - see the detailed instructions in the "Important: Grant Full Disk Access" section above.
The script needs to access:
~/Library/Messages/Attachments/(iMessage attachments)~/Pictures/Photos Library.photoslibrary/(Photos library)
If Photos import fails for a video:
- The script will skip that video and leave it in iMessage (not moved)
- Check the log file for details
- The video remains in its original location for safety
- You can manually import it later
Photos should automatically detect duplicates. If it doesn't:
- Check that "skip check duplicates false" is working
- You can manually delete duplicates in Photos
- All moved files are safe in the review folders
You can modify these settings at the top of the script:
MIN_SIZE_MB = 10 # Minimum video size to process
VIDEO_EXTENSIONS = ['.mov', '.mp4', '.m4v', '.avi'] # File types to process- This script never permanently deletes files - It only moves them to review folders
- No disk space duplication - Files are moved (not copied) to save space
- Review folders are your backup - Nothing is deleted until you manually delete the folders
- You control everything - Human approval for every single video
- Logging - Complete record of what was done
- Undo-friendly - Just move files back from review folders to restore
The script only processes videos β₯10MB. After completion:
- Videos are removed from
~/Library/Messages/Attachments/ - iMessage app will show less storage usage
- Videos remain safely in Photos and review folders
- No disk space is saved until you manually delete the review folders
- You can verify everything before permanently deleting the review folders
- Hash algorithm: SHA-256 (cryptographically secure)
- Duplicate detection: Conservative approach, relies on Photos' built-in detection
- GUI framework: Tkinter (included with Python)
- Photos integration: AppleScript for safe import
- Database access: Read-only SQLite queries to Photos library
If you encounter issues:
- Check the log file:
~/Desktop/iMessage_Cleanup_Log.txt - Review the inventory CSV for details about what was found
- The review folders contain all moved files if you need to restore them
- These are precious family videos - Take your time reviewing
- Don't delete review folders immediately - Wait a few weeks to be safe
- Spot-check Photos - Verify videos are actually there before final deletion
- Review folders are your only backup - Once deleted, videos are only in Photos
- When in doubt, choose "Skip" - Better safe than sorry
This script is provided as-is for personal use. No warranty expressed or implied.