Somehow I have duplicated a lot of photos and not just as thumbnails they seem to have been saved as masters but at about thumbnail size. I want to delete all the smaller ones based on same name and smaller size. This script sort of works but its check is based on pixels not size and as other things can effect the pixel count Would sooner the check was on actual size in KB or MB as appropriate.
tell application "iPhoto"
set Photo_ to 0
set NameCheck1 to {}
set NameCheck2 to {}
set Size1 to {}
set Size2 to {}
set Photo1 to {}
set Photo2 to {}
set SelectedPhotos to selection
if (count of SelectedPhotos) ≤ 0 then
display dialog "No Photos Selected"
else
set NoPhotos_ to count of items in SelectedPhotos --Retrun Photo in selection
display dialog "No Selected " & NoPhotos_
repeat with i from 1 to NoPhotos_ --loops through selcted Photos
set CurrPhoto to item i of SelectedPhotos --Selects Photo
if NameCheck1 = (name of CurrPhoto as string) then
set NameCheck2 to name of CurrPhoto as string
set Size2 to ((height of CurrPhoto) * (width of CurrPhoto)) / 2000 --size in Pixels
display dialog "Same Name occurred at " & i & return & "NameCheck1 " & NameCheck1 & " " & Size1 & return & "NameCheck2 " & NameCheck2 & " " & Size2
set NameCheck1 to {}
if Size1 > Size2 then
display dialog "Delete " & NameCheck2 & " " & Size2
else
display dialog "Delete " & NameCheck1 & " " & Size1
end if
else
set NameCheck1 to name of CurrPhoto as string
set Size1 to ((height of CurrPhoto) * (width of CurrPhoto)) / 2000
end if
end repeat
end if
end tell
Any ideas greatly appreciated thanks
Peter
You need to use the actual file size of each photo. The following script simply generates a list of file sizes of photos in an album named Composition. You can modify it to only deal with photos whose file size meets specific constraints.
set sizeList to {}
tell application "iPhoto"
repeat with eachImage in (get every photo in album "Composition")
set end of sizeList to my GetFileSize(eachImage's image path)
end repeat
end tell
sizeList
to GetFileSize(imgPath)
set finderPath to (POSIX file imgPath) as alias
tell application "Finder" to set fSize to size of finderPath
return fSize
end GetFileSize
Depending upon the version of iPhoto you are working with, however, determines what you can do with the images you select for deletion. The most recent version (9.4.2) does not allow AppleScript to either delete photos or move them into the iPhoto Trash.
I recommend that you move them into a specific folder, then select all of them (command-A), and then command-option-delete to move them into the iPhoto Trash.
Hi Craig
Many thanks for your suggestions this is what I did in the end, I had not appreciated that I could no longer delete or trash photos. It is however very slow so I may still not have done it the correct way.
tell application "iPhoto"
set curPhotos to selection
set theCount to 0
repeat with thisPhoto in curPhotos
set theCount to theCount + 1
get theCount
--display dialog theCount
if theCount = 1 then
set lastPhoto to thisPhoto
else
set thissize to size of (info for (image path of thisPhoto as POSIX file))
set lastSize to size of (info for (image path of lastPhoto as POSIX file))
set thisName to name of thisPhoto as string
set lastName to name of lastPhoto as string
--display dialog thisName & " " & lastName
if thisName = lastName then
--display dialog "Same Name"
if thissize ≥ lastSize then
set comment of thisPhoto to "Bigger"
set comment of lastPhoto to "Smaller"
else
set comment of thisPhoto to "Smaller"
set comment of lastPhoto to "Bigger"
end if
end if
set lastPhoto to thisPhoto
end if
end repeat
display alert "All photos same title checked for size"
end tell
thanks again
the help from this forum is great.
Peter