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

An iPhoto library rotation script Apps
My wife and I travel and photograph a lot. She is ahead of me with about 10,000 photos since I gave her a digital camera last year. iPhoto gets very slow with such large libraries. To allow easy switching FROM one library to another, I write a quick Perl script, named it photolib.command and put it in her dock. It is a non-GUI but relatively quick way have multiple libraries.

The first time it runs, you name your current library. FROM that point on "iPhoto Library" is just an alias to the real library folder.

To create a new blank library DELETE the "iPhoto Library" alias AFTER you have named your current library and re-run iPhoto. Duplicating and deleting library folders is done with with Finder.

Read the rest of the article for the script ... and note that this may very well not work with iPhoto2 when it's released in the near future!

Enter in your favorite editor:
#!/usr/bin/perl -w
use strict;

open(PS,"ps -auxjwww|");
my @processes=<PS>;
close PS;
if (grep(/iPhoto.app/,@processes)){
print "iPhoto is running. It is too dangerous to move the library.\n";
print "Quitting now.\n";
exit;
}
my $pictures="$ENV{'HOME'}/Pictures";
if (-l "$pictures/iPhoto Library"){
open(LS,"ls -l $pictures/iPhoto\\ Library|");
my $currentlib=<LS>;
close LS;
$currentlib =~ s/.*-> //;
chomp $currentlib;
print "The current library is : $currentlib\n";
} else {
if (-d "$pictures/iPhoto Library"){
print "The current library has not been named.\n";
print "Enter a one-word name for it: ";
my $newname=<STDIN>;
chomp $newname;
unless ($newname){
print "You chose no new name. Exiting.\n";
exit;
}

print "You have chosen to name the library \'$newname\'. Ok(yes/no)?\n";
my $response=<STDIN>;
if ($response =~ /yes/i){
if (-d "$pictures/$newname"){
print "A folder or library already exists with that name. Exiting.\n";
exit;
}
print "Now saving 'iPhoto Library' as \'$newname\'.\n";
system("mv $pictures/iPhoto\\ Library $pictures/$newname");
} else {
exec($0);
}
}
}

print "Available libraries are :\n";
open(DIR,"ls -l $pictures/*/Library.cache|");
my @librarylist=<DIR>;
close DIR;
my @libraries;
while(@librarylist){
my $lib=shift(@librarylist);
$lib =~ s|^.*$pictures/||;
$lib =~ s|/Library.cache||;
chomp($lib);
next if ($lib eq "iPhoto Library");
print "\t$lib\n";
push (@libraries,$lib);
}
print "Enter the library name to use, or just return to do nothing: ";
my $newlib=<STDIN>;
chomp($newlib);
if ($newlib){
if (-d "$pictures/$newlib"){
if (-l "$pictures/iPhoto Library"){
unlink "$pictures/iPhoto Library";
}
if (-d "$pictures/iPhoto Library"){
print "Sorry, current library was not yet named.\n";
exit;
}
system("cd $pictures;ln -s $newlib iPhoto\\ Library");
print "Library changed to $newlib\n";
} else {
print "Library $newlib does not exist.\n";
}
}
print "To rename, duplicate or DELETE a library, go to the Pictures\n";
print "folder with the Finder and do it.\n";
Name this with a ".command" extension and make sure it's executable.
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[6,762 views]  

An iPhoto library rotation script | 3 comments | Create New Account
Click here to return to the 'An iPhoto library rotation script' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
iApps and large libraries...
Authored by: silicondiode on Jan 11, '03 05:56:23PM

recent commentary here:

http://www.oreillynet.com/pub/wlg/2558

and something called "iPhoto Librarian" here:

http://homepage.mac.com/scrufmeister/iPhotoLibrarian.html



[ Reply to This | # ]
iphoto 2 fixes this
Authored by: tensai on Jan 13, '03 11:07:43AM

If ThinkSecret is to be believed, iPhoto 2 fixes this problem. As a person with thousands of photos, I'm equally invested in this problem -

http://www.thinksecret.com/news/ilifeiphoto2.html



[ Reply to This | # ]
IPhoto 2 Comments
Authored by: hmelton on Jan 31, '03 11:36:03PM

I've just downloaded iPhoto 2.

iPhoto 2 is still extremely sluggish with my wife's 2002 library which contains over 11500 pictures.
'photolib.command' still works fine to switch libraries, but I would suggest changing the two instances of 'Library.cache' to 'Library.data'. This allows the program to detect empty, unused iPhoto2 libraries.

here is a cvs diff.

Index: photolib.prl
===================================================================
RCS file: /Users/hmelton/CVSroot/utils/photolib.prl,v
retrieving revision 1.1
retrieving revision 1.3
diff -r1.1 -r1.3
47c47
< open(DIR,"ls -l $pictures/*/Library.cache|");
---
> open(DIR,"ls -l $pictures/*/Library.data|");
54c54
< $lib =~ s|/Library.cache||;
---
> $lib =~ s|/Library.data||;
73a74
> system("open /Applications/iPhoto.app");



[ Reply to This | # ]