Clean up empty albums in iPhoto

Have a relative that would like to automate a “cleanup” of iPhoto.

One of the things I’d like to automate is deleting the empty albums they somehow keep creating.

I’ve almost got this, but can’t figure out how to tell iPhoto to delete an empty album - could use a hint -


tell application "iPhoto"
	activate
	set theAlbums to get name of every album
	repeat with xal in theAlbums
		tell album xal
			try
				set photoCnt to count of photos
			on error theError
				set photoCnt to "0" as text
			end try
			try
				if photoCnt is not 0 then
					--do nothing
					display dialog "Photo Count of album " & xal & ":" & space & photoCnt
				else
					delete album xal of me
					display dialog "Deleted empty album " & xal
					exit repeat
				end if
			on error theError
				display dialog theError
			end try
		end tell
	end repeat
end tell



It’s these two lines that keep failing:

delete album xal of me
display dialog "Deleted empty album " & xal

Hi,

the delete an album use the remove command


tell application "iPhoto"
	activate
	set nameOfEmptyAlbums to name of (albums whose photos is {} and type is regular album)
	
	if (count nameOfEmptyAlbums) > 0 then
		set ASTID to AppleScript's text item delimiters
		set AppleScript's text item delimiters to return
		set listOfEmptyAlbums to nameOfEmptyAlbums as text
		set AppleScript's text item delimiters to ASTID
		repeat with aName in nameOfEmptyAlbums
			remove album aName
		end repeat
		display dialog "Empty albums deleted:" & return & return & listOfEmptyAlbums
	else
		display dialog "No empty albums found" buttons {"Cancel", "OK"} default button "OK"
	end if
end tell