If we regularly take screenshots on our desktop or in a particular folder, these images can accumulate over time and consume unnecessary disk space. Additionally, these screenshots can be difficult to find and edit later. However, setting the default screenshot folder on macOS and clearing this folder regularly can help solve these problems. In this article, you will learn how you can set the default screenshot folder and set an automatic task to clean this folder regularly.
Step 1: Set Default Screenshot Folder
To set the default screenshot folder, follow these steps:
- Open Terminal.
- Create the folder where you want the screenshots to be saved (for example, a folder named “Screenshots”).
- Then redirect the default screenshot folder to the specified folder using the following command:
defaults write com.apple.screencapture location ~/Desktop/Screenshots
This command specifies that screenshots will be saved in the “Screenshots” folder on the desktop.
4. Use the following command to enable the change:
`killall SystemUIServer`
Step 2: Set Task with cron
After setting the default screenshot folder, you can use cron
to clean this folder regularly. Edit your user crontab file using the crontab -e
command and add an entry about the schedule you want to periodically delete. For example, if you want to delete at 12:00 every day:
- Open terminal and type “crontab -e” command.
- Go to the first line and write the code below. You can customize the file folder and deletion frequency.
0 12 * * * rm -f ~/Desktop/Screenshots/*
- You can save and close the terminal with the “:x” command.
- You did it!
This command will delete the files in the “Screenshots” folder on the desktop every day at 12:00.
Better way
Serdar, one of the blog readers, has a better method. I would like to add this because I liked it very much, and I would also like to thank Serdar.
But I believe we can slightly improve it with a date filter because this version might cause some issues.
Say you take a screenshot at 11:59: It will be deleted in a minute. Or you’re looking for a screenshot you had just taken yesterday but it’s already gone in less than 24 hours.
So if we modify the cronjob (as below), only old enough files will be handled and the new ones will be kept for a while.
0 12 * * * find ~/Desktop/Screenshots/ -type f -mtime +7 -exec rm -f {} \;
(mtime +7: modified more than 7 days ago)
Conclusion
You should now have set the default screenshot folder in macOS and set an automatic task to clean this folder regularly. In this way, you can manage your screenshots more regularly and protect your unnecessary disk space. You can also easily find and organize your screenshots.