Applescript for Finding Duplicate Images and Deleting Small Files | In-Depth Guide
Summary – This article provides an in-depth guide on how to leverage Applescript to find duplicate images and delete small images on macOS. It covers the benefits of using Applescript, the step-by-step process of creating and running scripts, and tips for customizing the scripts to meet your needs. By following this guide, you can efficiently manage your photo library, removing unwanted duplicates and low-quality images.
Introduction
Keeping a clean photo library is never an easy task on a Mac, as there can be thousands of images. Duplicates and small, low-quality images of no value tend to creep in, taking up expensive storage and muddling your collection. Though several third-party applications can provide a solution for such issues, Applescript provides a native, flexible way to automate the process. It demonstrates how Applescript may be used to check for picture duplicates and remove small images, keeping everything organized in a photo library.
Understanding AppleScript
Before diving into the script, let’s discuss what AppleScript actually is. AppleScript is a scripting language developed by Apple to automate repeated tasks within macOS. It communicates with the operating system and various other applications to make it easier for the user to customize the workflow. Just in case users are dealing with huge picture collections, AppleScript becomes very useful in searching for duplicate images and deleting small images with less hassle.
Why Choose Applescript for Managing Images?
AppleScript is an incredibly powerful native script language for macOS, designed mainly to automate repetitive actions. It offers several benefits to image management:
- Personalization: Unlike generic software, Applescript enables one to custom-create the script to their needs, be it through the identification of duplicates based on file names, metadata, or any other criteria.
- Integration: Applescript integrates so well into the Mac environment that one can perform Automation tasks without requiring any applications.
- Efficiency: Since Applescript makes this whole process automatic, it scans hundreds of images in no time, saving you plenty of your time and effort.
Setting Up AppleScript
The following AppleScript will find all the duplicate images and then delete the small ones.
- Open Script Editor: First, open the Script Editor on a Mac. It is in the Utilities folder within the Applications folder.
- Write the Script: Below is a sample basic script on searching for duplicate images and getting rid of small files based on the user’s preference, e.g., based on small file size.
-- Define the folder containing your images set imageFolder to choose folder with prompt "Select the folder containing your images:" -- Get a list of all image files in the folder tell application "Finder" set imageFiles to every file of imageFolder whose name extension is "jpg" or name extension is "png" end tell -- Function to check for duplicate images based on file size and name on checkForDuplicates(imageList) set duplicates to {} repeat with i from 1 to (count of imageList) set currentImage to item i of imageList repeat with j from (i + 1) to (count of imageList) set comparisonImage to item j of imageList if (size of currentImage) is equal to (size of comparisonImage) and (name of currentImage) is not equal to (name of comparisonImage) then copy currentImage to the end of duplicates exit repeat end if end repeat end repeat return duplicates end checkForDuplicates -- Check for duplicate images set duplicateImages to checkForDuplicates(imageFiles) -- Delete duplicate images repeat with duplicates in duplicateImages tell application "Finder" delete duplicate end tell end repeat -- Delete small images below a certain size (e.g., 100KB) repeat with imageFile in imageFiles if (size of imageFile) < 100000 then tell application "Finder" delete imageFile end tell end if end repeat
display dialog “Process complete. Duplicates and small images have been removed.”
3. Personalize the Script: You can certainly adapt that script for your purposes. Examples might include altering the threshold of the file size at which tiny images are purged or adding more test criteria to determine duplicates, such as resolution and file creation date.
4. Run the Script: After you have customized the script, run it from the Script Editor by clicking the “Run” button. The script will ask you to select a folder containing images. Then, it will automatically find duplicate images and delete small images.
5. Check the Results: Once the script has finished running, you should take a look at the image folder and check all the images for the removal of duplicates and small images, as should have occurred. This step is evidently one of the most important in the whole process to make sure that your script is working fine and you are not accidentally deleting some important file.
Tips for Customizing Your Scripts
Applescript is flexible, and the above scripts can be extended to meet more elaborate requirements.
- Exclude Specific Folders: The script needs to be modified so that the specified subfolders in case such subfolders need to be kept out of the process.
- Logging: Add logging for further use in keeping track of all the moved and deleted files. It will definitely come in handy if you want to review the changes.
- Automatic Backup: Before running the script, there should be a backup of the Photo library in case something goes wrong with the data during processing.
Applescript Find and Delete Duplicate Images: Code-Free Alternative
Although AppleScript provides a very powerful way to find and clean out duplicate images, it requires prior coding knowledge. If that’s a bit too much for what you want to do, or if you don’t feel like getting into scripting, consider using SysTools Duplicate File Finder. This tool is designed to help you easily identify and remove duplicate images without writing or running scripts. This tool offers an intuitive interface, making it simple for anyone to clean up their photo library with ease and accuracy. It’s perfect for users who prefer a hassle-free solution for managing digital clutter, ensuring that all unwanted duplicates are efficiently removed from your system.
Conclusion
AppleScript provides a strong, native solution for managing duplicate and low-quality images on a Mac. By automating this process, you can keep your photo library clean and well-organized. However, not everyone is comfortable with scripting. For those who prefer a code-free solution, the above-mentioned duplicate file finder offers an easy-to-use alternative that simplifies the task of removing unwanted images. Whether you choose AppleScript for a customized approach or an automated solution for its user-friendly interface, both methods help maintain an organized and efficient photo library.
Also Read – Top 10 Free Best Duplicate Photo Finder & Remover Tool – 2024