Using AppleScript To Create Smart Albums In Photos Based On Resolution

- 3 mins read

Over the years I accumulated quite an amount of pictures and, as usual, they are hardly seen again once you copy them to the computer. To avoid this and making them easily accesible, I rely completely on the Mac Photos app from Apple.

This application uses AI to organise the media and tag people using face recognition. It also let you create “Smart Albums” allowing you to just set the filters according to your needs (Camera used, data, country, people or objects in the photo, etc.).

Something that doesn’t support is to filter the pictures based on the resolution of them, which it’s annoying for me because I have over 500GB of photos (For some it may not sound like a lot, but it is) and I wanted to have an album with only low resolution media. This would help me to discard, edit or upscale them in the future.

AppleScript To The Rescue

Using Mac you have access to a very powerful tool that is already built in your system, AppleScript.

AppleScript is a scripting language (Sounds scary, I know) developed and supported by Apple itself. This allows you to automate tasks or control applications by writing some lines of code. AppleScript’s syntax is a bit different from other languages as is similar to a natural language like English.

For this use case I used it to scan all my “Photos” Library and set a description like LOWRESOLUTION to all the media with less than 800px in height or width.

Using AppleScript To Create Smart Albums In Photos Based On Resolution

Then, by using the filter “Text” in Photos, I can create a Smart Album to only show those files.

Using AppleScript To Create Smart Albums In Photos Based On Resolution

The Script I Used

with timeout of 1800 seconds
	tell application "Photos" to ¬
		set the description of ¬
			(every media item whose ¬
				(height > width and height ≤ 800) or ¬
				(width > height and width ≤ 800)) to ¬
			"LOWRESOLUTION"
end timeout

display alert "Done."

As you can see, I wrapped the script with a modified timeout, as my Library is big and won’t work with the default value otherwise.

Potential Script Improvements

This code can be improved for higher fine-tuning on classifying different resolutions. Instead of writing LOWRESOLUTION, you can set LOWERTHAN800, LOWERTHAN600 and so on. This will let you filter further with Smart Albums.

The result, using variables, would be something like (You just need to change the maxSize value:

-- Set this property to the size you want
property maxSize : 800

with timeout of 1800 seconds
	tell application "Photos" to ¬
		set the description of ¬
			(every media item whose ¬
				(height > width and height ≤ maxSize) or ¬
				(width > height and width ≤ maxSize)) to ¬
			"LOWERTHAN" & maxSize
end timeout

display alert "Done."

Share: Link copied to clipboard

Tags:

Where: Home > Personal > Using AppleScript To Create Smart Albums In Photos Based On Resolution