AppleScript error when attempting to delete empty albums in Photos.app

applescriptphotosphotos.app

The Problem

I’m trying to delete a bunch of empty albums using AppleScript. I have verified that I am “getting”/“collecting”/whatever-appropriate-terms-you-prefer the correct albums.

But when I try to delete these empty albums, I get an error along these lines:

error "Can’t make item 1 of every album of 
folder id \"wFSS4tONSgyq4NWwnUthVA\" of folder id \"6Aod8RunTj+3Nsz2jmM1xA\" 
into type integer." number -1700 from item 1 of every album of folder id
"wFSS4tONSgyq4NWwnUthVA" of folder id "6Aod8RunTj+3Nsz2jmM1xA" to integer

The same error occurs whether I try to delete the empty albums while I am looping through my albums and checking whether each one is empty, or if I collect the empty albums into a list and use a second loop to delete the albums in the list.

What is going on? The documentation clearly states “only albums and folders can be deleted”.

My Code

repeat with project_folder in PROJECTS_SUBFOLDERS
    --log "PROJECT FOLDER: " & project_folder's name & ¬
    --"\nID: " & project_folder's id

    if (count of project_folder's albums) is greater than 0 then
        --log "\n"
        --log project_folder's name as text
        --log project_folder's id as text
        --log ""

        repeat with abm in project_folder's albums
            --log "Class: " & abm's class as text
            --log "Album: " & abm's name as text
            --log "ID: " & abm's id as text

            if (count of abm's media items) is equal to 0 then
                --log (count of abm's media items)
                log abm's name as text
                set the end of empty_albums to abm
            end if
        end repeat
    end if
end repeat


log "now, to delete..."

repeat with abm in empty_albums
    log "Deleting " & abm's name as text
    delete album abm  
    -- (I have also tried `delete abm` without success)
end repeat

return

This code is the 2-loop method, but the same occurs if I try to delete empty albums without collecting them into a list first.

Can somebody please tell me what’s going on?!

Can anybody tell me how to get this script to run successfully?

Best Answer

The solution is to change:

delete abm
-- or delete album abm

To this:

delete album id (abm's id)

Nothing in library documentation would have lead me to this answer. I was just trying anything out of desperation.