set dialogResult to display dialog ¬ "Enter the file size threshold for small photos or videos in kB : " buttons {"Cancel", "OK"} ¬ default answer (defaultFileSizeThreshold as text) set FileSizeThresholdkB to (text returned of dialogResult) as integer -- file size in kB set FileSizeThreshold to FileSizeThresholdkB * 1024 -- file size in Byte set photosNotInAnyAlbumName to "photosNotInAnyAlbum" -- the album to collect all photos not in any album tell application "Photos" activate -- Ensure that the albums do exist try set imageSel to (get selection) on error errTexttwo number errNumtwo display dialog "Cannot get the selection: " & errNumtwo & return & errTexttwo end try -- return the size of the first item of imageSel try if not (exists container photosNotInAnyAlbumName) then make new album named photosNotInAnyAlbumName end if set theAlbumWithPhotosNotInAnyAlbum to container photosNotInAnyAlbumName if not (exists container "SkippedPhotos") then make new album named "SkippedPhotos" end if set theSkippedAlbum to container "SkippedPhotos" on error errTexttwo number errNumtwo display dialog "Cannot open albums: " & errNumtwo & return & errTexttwo end try -- process the selected photos from the All Photos album set photosNotInAnyAlbum to {} -- the list of small photos -- check, if the album o if imageSel is {} then error "Please select some images." else repeat with im in imageSel try tell im --get the file size set pictureId to its id set names to name of (albums whose id of media items contains pictureId) end tell on error errText number errNum display dialog "Error: " & errNum & return & errText & "Trying again" try delay 2 tell im set pictureId to its id set names to name of (albums whose id of media items contains pictureId) end tell on error errTexttwo number errNumtwo display dialog "Skipping image due to repeated error: " & errNumtwo & return & errTexttwo end try end try set inNoAlbum to (names is missing value) if inNoAlbum then set photosNotInAnyAlbum to {im} & photosNotInAnyAlbum end if end repeat add photosNotInAnyAlbum to theAlbumWithPhotosNotInAnyAlbum return "Photos not in any album: " & (length of photosNotInAnyAlbum) end if end tell