The following script recursively lists the content of an Aperture library. The output is simple, for demonstration puposes, but could be modified to XML. If the XML were that of a PLIST, the Apple Property List viewer oculd be used to diaplsy the output.
A simlar script produces all of the keywords and tags for all of the images in Aperture.
The scripts run much faster in the shell than in the AppleScript Editor bcause the shwll produces no debugging or monitoring information.
#!/usr/bin/env osascript
(* Demo: list the containment hierarchy in Aperture, starting from libraries.
Runs from AppleScript Editor, or as a shell command
References:
Aperture 3 AppleScript Reference Manual,
particularly the Containment Diagram in Appendix A
from the link on "Aperture Resources" web page at http://images.apple.com/aperture/resources/
Aperture AppleScript Dictionary, accessed from AppleScript Editor
Ian E. Gorman
*)
global outputFile
set outputFilePath to "/Users/ian/prj/sw/AppleScript/ApertureContainment.txt"
global lineEnd
set lineEnd to "
"
global tabChar
set tabChar to " "
on writeText(str)
write str to outputFile
end writeText
# Open the file, guarantee closure after any error, and list the contents of Aperture libraries
try
set outputFile to open for access POSIX file outputFilePath with write permission
set eof outputFile to 0 # truncate the file, if it already exists
my listAll()
close access outputFile
on error errorMsg number errNum from offendingObj partial result resutList to expectedType
try
display alert "Operation failed, attempting to close output file" & lineEnd & "Error number " & errNum & ": " & errorMsg
close access outputFile
display alert "Operation failed, but output file has been closed"
on error
display alert "Operation failed, also failed to close output file"
end try
end try
# top-level in Aperture
on listAll()
tell application "Aperture"
repeat with eachLibrary in libraries
my listLibrary(0, eachLibrary)
end repeat
end tell
end listAll
on listLibrary(level, thisLibrary)
local newLevel
set newLevel to 1 + (level as integer)
tell application "Aperture"
my writeText((newLevel as rich text) & tabChar & "library" & tabChar & (name of thisLibrary) & lineEnd)
repeat with eachAlbum in albums of thisLibrary
my listAlbum(newLevel, eachAlbum)
end repeat
repeat with eachFolder in folders of thisLibrary
my listFolder(newLevel, eachFolder)
end repeat
repeat with eachProject in projects of thisLibrary
my listProject(newLevel, eachProject)
end repeat
repeat with eachImageVersion in image versions of thisLibrary
my listImageVersion(newLevel, eachImageVersion)
end repeat
end tell
end listLibrary
on listAlbum(level, thisAlbum)
local newLevel
set newLevel to 1 + (level as integer)
tell application "Aperture"
my writeText((newLevel as rich text) & tabChar & "album" & tabChar & (name of thisAlbum) & lineEnd)
repeat with eachImageVersion in image versions of thisAlbum
my listImageVersion(newLevel, eachImageVersion)
end repeat
end tell
end listAlbum
on listFolder(level, thisFolder)
local newLevel
set newLevel to 1 + (level as integer)
tell application "Aperture"
my writeText((newLevel as rich text) & tabChar & "folder" & tabChar & (name of thisFolder) & lineEnd)
repeat with eachAlbum in albums of thisFolder
my listAlbum(newLevel, eachAlbum)
end repeat
repeat with eachFolder in folders of thisFolder
my listFolder(newLevel, eachFolder)
end repeat
repeat with eachProject in projects of thisFolder
my listProject(newLevel, eachProject)
end repeat
repeat with eachImageVersion in image versions of thisFolder
my listImageVersion(newLevel, eachImageVersion)
end repeat
end tell
end listFolder
on listProject(level, thisProject)
local newLevel
set newLevel to 1 + (level as integer)
tell application "Aperture"
my writeText((newLevel as rich text) & tabChar & "project" & tabChar & (name of thisProject) & lineEnd)
repeat with eachAlbum in albums of thisProject
my listAlbum(newLevel, eachAlbum)
end repeat
repeat with eachSubfolder in subfolders of thisProject
my listSubfolder(newLevel, eachSubfolder)
end repeat
repeat with eachImageVersion in image versions of thisProject
my listImageVersion(newLevel, eachImageVersion)
end repeat
end tell
end listProject
on listSubfolder(level, thisSubfolder)
local newLevel
set newLevel to 1 + (level as integer)
tell application "Aperture"
my writeText((newLevel as rich text) & tabChar & "subfolder" & tabChar & (name of thisSubfolder) & lineEnd)
repeat with eachAlbum in albums of thisSubfolder
my listAlbum(newLevel, eachAlbum)
end repeat
repeat with eachSubfolder in subfolders of thisSubfolder
my listSubfolder(newLevel, eachSubfolder)
end repeat
repeat with eachImageVersion in image versions of thisSubfolder
my listImageVersion(newLevel, eachImageVersion)
end repeat
end tell
end listSubfolder
on listImageVersion(level, thisImageVersion)
local newLevel
set newLevel to 1 + (level as integer)
tell application "Aperture"
my writeText((newLevel as rich text) & tabChar & "image version" & tabChar & (name of thisImageVersion) & lineEnd)
end tell
end listImageVersion