Apple Aperture: image versions not deleted...

… although the delete command is executed successfully. My script is as follows:


property YourProject: "Your_Project" -- the name of any project which you know for sure contains duplicates.
tell application "Aperture"
	tell project YourProject
		set AllImages to image versions
		set ImageSet_1 to {}
		set ImageSet_2 to {}
		repeat with i from 1 to (the number of items in AllImages)
			set TheImage to item 1 of AllImages
			set end of ImageSet_1 to name of TheImage
			set RestOfImages to the rest of AllImages
			repeat with j from 1 to number of items in RestOfImages
				set DuplicateCandidate to item j of RestOfImages
				if DuplicateCandidate's name is in ImageSet_1 then set end of ImageSet_2 to DuplicateCandidate
			end repeat
			set AllImages to RestOfImages
		end repeat
	end tell
	repeat with i from 1 to number of items in ImageSet_2
		delete item i of ImageSet_2
	end repeat
end tell

ScriptEditor’s Events and Replies pane shows the delete command deleting versions but in fact those aren’t deleted, still remains in the project, not moved to Aperture’s Trash. Why is that?

Model: macBook Pro mid2012 15" - Core i7 2.3 Ghz - 16 GB DDR3 1600 Mhz - 1TB SSD
AppleScript: 2.2.1
Browser: Safari 534.57.7
Operating System: macOS 10.7

What happens when you just get an ‘image version’ id and try to delete it? Everything above that is incidental. As an aside on the matter of generating your list, do your versions have peculiar names? When I create one, the word ‘Version’ is added to the original’s name. Couldn’t you just grab every image version whose name contains "Version"?

FWIW, I get the impression that Aperture doesn’t let applescript’s delete command work on images, only stuff like keywords, for example. ‘Delete’ is not one of the commands that ‘image versions’ responds to (but I don’t know whether that is an absolute restriction).

You may have to delete them manually or maybe try filtering and then using key codes (e.g. key code 51 using command down — for command-delete). I tried moving something to the trash rather than deleting but couldn’t figure out how to reference the trash usefully.

I corrected my script’s logic because the original one had flaws. I double-checked it filters out duplicates by plugging in my handlers library containing a deduping handler as a script object. I then rewrote my original script accordingly, ran it and the delete command still wasn’t able to delete these duplicate image versions actually!

Corrected script:


property YourProject: "NameOfYourProject" -- the name of any project of yours with duplicate image versions

tell application "Aperture"
	tell project YourProject
		set AllImages to image versions
		set Duplicates to {}
		repeat with i from 1 to (the number of items in AllImages)
			set ComparedImage to item 1 of AllImages
			set RestOfImages to the rest of AllImages
			repeat with j from 1 to number of items in RestOfImages
				set DuplicateCandidate to item j of RestOfImages
				if DuplicateCandidate's name is equal to ComparedImage's name then set end of Duplicates to DuplicateCandidate
			end repeat
			set AllImages to RestOfImages
		end repeat
	end tell
repeat with i from 1 to number of items in Duplicates
		delete item i of Duplicates
	end repeat
	
end tell

Model: macBook Pro mid2012 15" - Core i7 2.3 Ghz - 16 GB DDR3 1600 Mhz - 1TB SSD
AppleScript: 2.2.1
Browser: Safari 534.57.7
Operating System: macOS 10.7