We've finished our move from .Mac to our very own domain name: http://www.brettgrossphotography.com/ .

Woo hoo!




Clean Deleted Images Folders

Current version: v2 02
Built on: Aperture 1.5.2

Just like any responsible Aperture user, I use Vaults. I also use the
Shoot->Library->Referenced workflow and discovered that there were some odd (and large) folders on the drives that house my Vaults. These folders seemed to contain images that already exist elsewhere- usually in the folder that houses all of my referenced masters.

I did a little detective work...

Here is what I learned.

In a nutshell, any image that was in the Library when it was backed up to a Vault and then not in the Library on a subsequent update (ie should be deleted from the Vault) is moved to that Vault's deleted items folder. Items can be removed from the Library in a few ways but the 2 that I've seen are:
1- Image in Library is deleted
2- Image is imported into Library and migrated to Referenced status (and thus no longer in the Library and no longer backed up via Vaults)

My AppleScript (below) asks for a folder that contains all referenced masters (which is what I do...) and trawls every mounted volume for Vault deleted items and checks to see if the images in those folders are, indeed, in the referenced master folder hierarchy somewhere. If they are then the image is deleted otherwise they are left alone.

As usual, this script does exactly what I want but probably not what anyone else wants so feel free to customize:
Download


--
-----------------------------------------------------------------------------------------------
--
Forked from Clean Deleted Images 04 on 2007-04-13
--



--
-----------------------------------------------------------------------------------------------
on run
set numDel to 0

tell application "Finder"
--
---------------------------------------- Choose the root folder containing our referenced images
try
set defaultFolder to (folder "Digipics" of disk "RovingPhotos")
set defaultAlias to defaultFolder as alias
on error
set defaultFolder to home folder
set defaultAlias to defaultFolder as alias
end try
end tell

set refRoot to choose folder with prompt "Choose the folder that contains your referenced masters:" default location defaultAlias
log refRoot
set refPOSIX to POSIX path of refRoot
log refPOSIX

tell application "Finder"
set theDisks to list disks

--
-------------------------------------------- Process every mounted disk
repeat with curDisk in theDisks
set theNames to (name of items of disk curDisk)

repeat with curName in theNames
if curName ends with ".apvault" then

ignoring application responses
tell application "System Events"
display dialog ("Processing Deleted Items for Vault " & curName & " on disk " & curDisk) buttons {"OK"} default button 1 giving up after 5
end tell
end ignoring

log ("Processing Vault: " & curName)
--
---------------------------------- Process the items in deleted images folder

set baseName to (text 1 through -9 of curName)
set deletedName to (baseName & " Deleted Images")
log baseName

set rootAlias to (folder deletedName of disk (contents of curDisk)) as alias

copy (entire contents of (folder deletedName of disk (contents of curDisk))) to allDelFiles
repeat with curFile in allDelFiles
--
try
set theKind to (kind of curFile) as string
log theKind

if theKind is not "folder" then
set curName to name of curFile

--
------------------------- look for the file
set theScript to "/usr/bin/find " & (quoted form of refPOSIX) & " -name " & (quoted form of curName) & " -print"
log theScript
set theOut to do shell script theScript


if ((count of paragraphs of theOut) is greater than 0) then
log "File found. Should be safe to delete it."
set label index of curFile to 4
delete curFile
set numDel to numDel + 1

else
log "File not found. Should probably keep it"
set label index of curFile to 3

end if
end if
--
end try
end repeat -- ----------- with curFile in allDelFiles

my trimEmpties(rootAlias, false)
end if

end repeat -- ---------- with curName in theNames
end repeat -- ---------- with curDisk in theDisks

display dialog ("Done!" & return & return & (numDel & " files moved to the trash.")) buttons {"OK"} default button 1 giving up after 60

end tell -- ------------ Finder
end run



--
------------------------------------------------------------------------------------
on trimEmpties(rootFolder, delRoot)
tell application "Finder"

set allItems to (items of rootFolder)

if (((count of allItems) is 0) and (delRoot is true)) then
delete rootFolder

else
set allFolders to folders of rootFolder
repeat with curFolder in allFolders
set curAlias to (contents of curFolder) as alias
my trimEmpties(curAlias, true)

end repeat
end if

--
-------- Check again to see if the rootFolder is now empty
set allItems to (items of rootFolder)
if (((count of allItems) is 0) and (delRoot is true)) then
delete rootFolder
end if

end tell
end trimEmpties