Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Reuniting iPhoto libraries not on cd?' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Reuniting iPhoto libraries not on cd?
Authored by: jaysoffian on Feb 04, '04 07:40:46PM

I'm somewhat hesitant to post this since it's a partial solution, but it worked for me. Use script editor to compile the following Applescript and then save it as an application bundle. Start up iPhoto4 then double-click this applet to run it.

The applet assumes you have already imported all your photos from your multiple iPhoto2 libraries. That's the part of this solution that's not complete - for me importing the photos was easy because I've always archived my photos (into a folder by day) *before* importing into iPhoto. So I simply needed to recreate my albums in iPhoto4 once I had re-imported all my photos from their original archive location.

Anyway, you run this applet and then point it at your existing iPhoto2 libraries (if you have multiple iPhoto2 libraries, you may want to put them all inside a single top-level folder first and then point this applet at the top-level folder, that way it can scan all the libraries at once). This applet will then recreate all the albums it finds in your existing iPhoto2 libraries inside of your iPhoto4 library. Note that all this does is recreate your albums. Any other information inside your iPhoto2 library is *NOT* carried over.

I hope this is helpful - maybe it can serve as a starting point for someone to work on a more complete solution.


on run
	importAlbumsFromLibrary(choose folder with prompt "Choose an iPhoto Library to import:")
end run

on open what
	global shouldQuit
	set shouldQuit to false
	set theLibraries to {}
	tell application "Finder"
		repeat with f in what
			if kind of f is "folder" then set theLibraries to theLibraries & f
		end repeat
	end tell
	repeat with theLibrary in theLibraries
		importAlbumsFromLibrary(theLibrary)
		if shouldQuit then exit repeat
	end repeat
end open

on importAlbumsFromLibrary(theLibrary)
	global tempFile
	global shouldQuit
	set shouldQuit to false
	set theLibrary to quoted form of POSIX path of theLibrary
	set tempFile to do shell script "/usr/bin/mktemp -t /tmp"
	try
		set theScript to "find " & theLibrary & " -type l -path '*/Albums/*' | sed 's/.*\\/Albums\\///' | tee " & tempFile & " | cut -f1 -d/ | sort -u"
		set theAlbumNames to paragraphs of (do shell script theScript)
		repeat with theKey in theAlbumNames
			set theScript to "awk -v album=" & quoted form of theKey & " -F/ '$1 == album {print $2}' " & tempFile
			set theImageNames to paragraphs of (do shell script theScript)
			set theAlbumName to (do shell script "echo " & quoted form of theKey & "| sed 's/:/\\//g'")
			tell application "iPhoto"
				if not (exists album theAlbumName) then
					new album name theAlbumName
				end if
				select album theAlbumName
				repeat with theImageName in theImageNames
					if not (exists (some photo of album theAlbumName whose image filename is theImageName)) then
						add (first photo whose image filename is theImageName) to album theAlbumName
					end if
					if shouldQuit then error
				end repeat
			end tell
		end repeat
		cleanup()
	on error e number n partial result p from f to t
		cleanup()
		error e number n partial result p from f to t
	end try
end importAlbumsFromLibrary

on quit {}
	global shouldQuit
	set shouldQuit to true
	continue quit
end quit

on cleanup()
	global tempFile
	do shell script "rm -f " & tempFile
end cleanup


[ Reply to This | # ]