diff -Naur Mac-Glue-1.23/Glue.pm new/Glue.pm
--- Mac-Glue-1.23/Glue.pm	Sun Feb 20 01:20:12 2005
+++ new/Glue.pm	Wed Mar  2 01:14:05 2005
@@ -4,7 +4,7 @@
 # venturing within.  it might seem reasonable at first, but then you
 # get sucked in and it's all over.
 
-use Mac::Glue::Common qw($MACGLUEDIR);
+use Mac::Glue::Common qw(domain_dirs domain_read);
 use Carp;
 use Exporter;
 use Fcntl;
@@ -131,16 +131,24 @@
 	my($class, $app, $addtype, @add) = @_;
 	my($self, $glue, $db, $app1, $app2);
 
-	# find glue, try a few different names just in case
+	# find glue, try a few different names just in case, in all domains
 	($app1 = $app) =~ tr/ /_/;
 	($app2 = $app) =~ tr/_/ /;
-	for (map { catfile($MACGLUEDIR, $_) } $app, $app1, $app2) {
+	for my $gluedir (domain_dirs domain_read) {
+		for (map { catfile($gluedir, $_) } $app, $app1, $app2) {
 		if (-e) {
 			$glue = $_;
 			last;
 		}
 	}
-	croak "No application glue for '$app' found in '$MACGLUEDIR'" unless $glue;
+	}
+	
+	unless ($glue) {
+		my %dirhash = map { "'" . $_ . "'" => 1 } domain_dirs domain_read;
+		my @alldirs = keys %dirhash;
+		croak "No application glue for '$app' found in " .
+			join(", ", @alldirs);
+	}
 
 	# if not already opened, open and store reference to db
 	unless (exists $OPENGLUES{$glue}) {
@@ -1336,31 +1344,43 @@
 sub _open_others {
 	chomp(my $curdir = `pwd`);
 	my @others;
-	for my $dir (map { catfile($MACGLUEDIR, $_) } qw[dialects additions]) {
-		unless (-e $dir) {
+	for my $subdir (qw(dialects additions)) {
+		my $seensub = 0;
+		
+		# Hope it's ok to open two separate glues for the "same" addition?
+		for my $gluedir (domain_dirs domain_read) {
+			my $dir = catfile($gluedir, $subdir);
+			next unless -e $dir;
+			$seensub = 1;
+
+			local *DIR;
+			opendir DIR, $dir or confess "Can't open directory '$dir': $!";
+			chdir $dir or confess "Can't chdir directory '$dir': $!";
+	
+			# add file type / creator checking ???
+			# maybe add a new file type for glues?  i can do that now,
+			# because i am special or something.
+			for (readdir DIR) {
+				next if -d;
+				next if $_ eq "Icon\015";
+				next if /\.pod$/;
+				tie my %db, 'MLDBM', $_, O_RDONLY
+					or confess "Can't tie '$_': $!";
+				push @$OTHEREVENT, $db{EVENT} if $db{EVENT};
+				push @$OTHERCLASS, $db{CLASS} if $db{CLASS};
+				push @$OTHERENUM,  $db{ENUM}  if $db{ENUM};
+			}
+		}
+		
+		unless ($seensub) {
 			warn "Please run gluedialect and gluescriptadds programs"
 				unless $Mac::Glue::CREATINGGLUES;
 			$Mac::Glue::NEEDCREATE = 1;
-			next;
-		}
-
-		local *DIR;
-		opendir DIR, $dir or confess "Can't open directory '$dir': $!";
-		chdir $dir or confess "Can't chdir directory '$dir': $!";
-
-		# add file type / creator checking ???
-		# maybe add a new file type for glues?  i can do that now,
-		# because i am special or something.
-		for (readdir DIR) {
-			next if -d;
-			next if $_ eq "Icon\015";
-			next if /\.pod$/;
-			tie my %db, 'MLDBM', $_, O_RDONLY or confess "Can't tie '$_': $!";
-			push @$OTHEREVENT, $db{EVENT} if $db{EVENT};
-			push @$OTHERCLASS, $db{CLASS} if $db{CLASS};
-			push @$OTHERENUM,  $db{ENUM}  if $db{ENUM};
 		}
 	}
+	
+	
+	
 	chdir $curdir or confess "Can't chdir to '$curdir': $!";
 }
 
@@ -1729,15 +1749,24 @@
 parse an application's AETE resource, and the glue is written out to a
 file using Storable, DB_File, and MLDBM.  Glues are saved in
 $ENV{MACGLUEDIR} (which is defined when Mac::Glue is used if it is not
-defined already).  By default for MacPerl, glues are stored in
-F<:site_perl:Mac:Glue:glues:>, or in F<./Glue/glues> relative to
-F<Glue.pm> for Unix (Mac OS X).
+defined already). By default for MacPerl, glues
+are stored in F<:site_perl:Mac:Glue:glues:>.
+
+For Unix (Mac OS X), different paths can be specified for glues installed
+at installation of Mac::Glue (the I<system> domain), other glues installed
+for the whole system (I<local> domain), and glues installed for specific
+users (I<user> domain). These locations can be specified as
+colon-separated paths in $ENV{MACGLUEDIRS}. The default locations are,
+respectively, the directory F<./Glue/glues> relative to F<Glue.pm>,
+F</Library/Glues>, and F<$HOME/Library/Glues>. The location for the
+I<system> domain can be specified in $ENV{MACGLUEDIR} if it is not
+overridden by $ENV{MACGLUEDIRS}.
 
 All glues have access to the global scripting additions and dialect
 information.  Glues for these must be created as well, and are created
 with the F<gluescriptadds> and F<gluedialect> programs, which are
-similar to the F<gluemac> program.  They are saved in the directories
-F<$ENV{MACGLUEDIR}additions> and F<$ENV{MACGLUEDIR}dialects>.
+similar to the F<gluemac> program.  They are saved in the subdirectories
+F<additions> and F<dialects> relative to where regular glues are saved.
 
 Along with the glue file is a POD file containing documentation for the
 glue, listing all the events (with parameters), classes (with
diff -Naur Mac-Glue-1.23/lib/Mac/Glue/Common.pm new/lib/Mac/Glue/Common.pm
--- Mac-Glue-1.23/lib/Mac/Glue/Common.pm	Tue Dec  7 01:24:37 2004
+++ new/lib/Mac/Glue/Common.pm	Wed Mar  2 01:09:49 2005
@@ -25,11 +25,12 @@
 
 use base 'Exporter';
 use vars qw(
-	@EXPORT $REVISION $VERSION $MACGLUEDIR
+	@EXPORT $REVISION $VERSION %MACGLUEDIRS
 	$PROGNAME $PROGVERSION $PROGDESC $PROGOPTS
+	$PROGUSEDOMAIN
 );
 
-@EXPORT = qw(glue is_osax is_dialect opts $MACGLUEDIR);
+@EXPORT = qw(glue is_osax is_dialect opts domain_read domain_write domain_dirs);
 ($REVISION) 	= ' $Revision: 1.5 $ ' =~ /\$Revision:\s+([^\s]+)/;
 $VERSION	= '1.01';
 
@@ -37,22 +38,41 @@
 $PROGVERSION ||= $VERSION;
 $PROGDESC    ||= '';
 $PROGOPTS    ||= '';
-$MACGLUEDIR    = $ENV{MACGLUEDIR};
+$PROGUSEDOMAIN ||= 0; # Allow specifying the domain on the CLI?
+my $macgluedir = $ENV{MACGLUEDIR};
 
+my @alldomains = qw(user local system);
 if ($^O eq 'MacOS') {
-	$MACGLUEDIR ||= "$ENV{MACPERL}site_perl:Mac:Glue:glues:";
-	$MACGLUEDIR  .= ':' unless $MACGLUEDIR =~ /:$/;
-} elsif (!$MACGLUEDIR) {
-	my $dir = dirname $INC{'Mac/Glue/Common.pm'};
-	unless (file_name_is_absolute($dir)) {
-		require Cwd;
-		$dir = catdir(Cwd::cwd(), $dir);
+	$macgluedir ||= "$ENV{MACPERL}site_perl:Mac:Glue:glues:";
+	$macgluedir  .= ':' unless $macgluedir =~ /:$/;
+	
+	%MACGLUEDIRS = map { $_ => $macgluedir } @alldomains;
+} else {
+	if (!$macgluedir) {
+		my $dir = dirname $INC{'Mac/Glue/Common.pm'};
+		unless (file_name_is_absolute($dir)) {
+			require Cwd;
+			$dir = catdir(Cwd::cwd(), $dir);
+		}
+		$macgluedir = catdir($dir, 'glues');
+	}
+	
+	my $gluedirs = $ENV{MACGLUEDIRS};
+	my @gluedirs = $gluedirs ? (split /:/, $gluedirs) : ();
+	if (scalar(@gluedirs) != 3) {
+		my $libloc = "/Library/Glues"; # Can't have spaces, perldoc sucks
+		@gluedirs = (
+			$macgluedir,			# system
+			$libloc,				# local
+			$ENV{HOME} . $libloc	# user
+		);
 	}
-	$MACGLUEDIR = catdir($dir, 'glues');
+	@MACGLUEDIRS{@alldomains} = reverse @gluedirs;
 }
 
+
 # in case old code uses it ...
-$ENV{MACGLUEDIR} = $MACGLUEDIR;
+$ENV{MACGLUEDIR} = $macgluedir;		
 
 sub glue {
 	my($opts, $files, $type) = @_;
@@ -61,7 +81,7 @@
 
 	local $MacPerl::Target = '' if $^O ne 'MacOS';
 
-	my @dirs = $MACGLUEDIR;
+	my @dirs = ( domain_dirs(domain_write()) )[0];
 	my $class = 'Mac::AETE::App';
 	if ($type eq 'dialect') {
 		push @dirs, 'dialects';
@@ -171,14 +191,59 @@
 
 sub opts {
 	my %opts;
-	my $opts = $PROGOPTS . 'hvI';
+	my $opts = $PROGOPTS . 'hvI' . ($PROGUSEDOMAIN ? 'D:' : '');
 	usage('Options used incorrectly') unless getopts($opts, \%opts);
 	usage() if $opts{'h'};
 	version() if $opts{'v'};
+	set_domain($opts{'D'}) if $PROGUSEDOMAIN;
 	return \%opts;
 }
 
+
+{
+	# The domain for reading
+	my $rdomain;
+	
+	# The domain for writing
+	my $wdomain;
+	
+	# Setup the domain
+	sub set_domain {
+		my $dom = shift;
+		
+		$rdomain = $wdomain = $dom
+			if defined $dom && $dom =~ /^(system|local|user)$/;
+		return if defined $rdomain && defined $wdomain; # Don't recalc
+		
+		# By default write domain is local if it's writeable, otherwise user.
+		# Read domain is user by default.
+		$wdomain = (-w $MACGLUEDIRS{local}) ? 'local' : 'user';
+		$rdomain = 'user';
+	}	
+	
+	sub domain_read {
+		set_domain();
+		return $rdomain;
+	}
+	
+	sub domain_write {
+		set_domain();
+		return $wdomain;
+	}
+	
+	# Get the dirs to look in for a given domain
+	sub domain_dirs {
+		my $dom = shift;
+		my @doms = @alldomains;
+		shift @doms while @doms && $doms[0] ne $dom; 
+		return @MACGLUEDIRS{@doms};
+	}
+}		
+
 sub usage {
+	my $domainusage = ($PROGUSEDOMAIN ? <<EOT : '');
+	-D domain	The domain to store glue files: system, local or user
+EOT
 	print "*** $_[0]\n" if $_[0];
 	# Remember to doublecheck these match getopts()!
 	print <<EOT;
@@ -188,6 +253,7 @@
 	-h	Help (this message)
 	-v	Version
 	-I	Do not prompt, use defaults
+$domainusage
 
 EOT
 	exit;
diff -Naur Mac-Glue-1.23/make_glues new/make_glues
--- Mac-Glue-1.23/make_glues	Wed May 19 11:58:41 2004
+++ new/make_glues	Wed Mar  2 01:08:36 2005
@@ -9,15 +9,15 @@
 push @apps, 'sevs', 'imev' if $^O ne 'MacOS';
 my @paths = map { $Application{$_} } @apps;
 
-system($^X, $lib, "$script/gluedialect", '-I');
+system($^X, $lib, "$script/gluedialect", '-I', '-D', 'system');
 
-my $aout = `$^X $lib $script/gluescriptadds -I 2>&1`;
+my $aout = `$^X $lib $script/gluescriptadds -I -D system 2>&1`;
 while ($aout =~ s!(?:^|\n).+does not appear to be an addition.+?\n  Try: blib/script/gluemac '(.+?)'\n!\n!) {
 	push @paths, $1;
 }
 $aout =~ s/^\n+//;
 print $aout;
 
-system($^X, $lib, "$script/gluemac", '-I', @paths);
+system($^X, $lib, "$script/gluemac", '-I', '-D', 'system', @paths);
 
 __END__
diff -Naur Mac-Glue-1.23/scripts/gluedialect.PL new/scripts/gluedialect.PL
--- Mac-Glue-1.23/scripts/gluedialect.PL	Sat May  3 21:09:47 2003
+++ new/scripts/gluedialect.PL	Wed Mar  2 01:08:36 2005
@@ -32,6 +32,7 @@
 Read the documentation for created glues with the gluedoc program (for
 dialects, use the -d switch).
 EOT
+	$Mac::Glue::Common::PROGUSEDOMAIN = 1;
 }
 
 use File::Spec::Functions;
diff -Naur Mac-Glue-1.23/scripts/gluedoc.PL new/scripts/gluedoc.PL
--- Mac-Glue-1.23/scripts/gluedoc.PL	Wed May 19 03:27:26 2004
+++ new/scripts/gluedoc.PL	Wed Mar  2 01:08:36 2005
@@ -76,7 +76,8 @@
 
 my %list;
 OUTER: for my $dir (@dirs) {
-	my $d = catfile($MACGLUEDIR, $dir);
+	for my $domdir (domain_dirs domain_read) {
+		my $d = catfile($domdir, $dir);
 	opendir my $dh, $d or die $!;
 	for my $f (readdir $dh) {
 		if ($opts->{'L'} && $f =~ /\.pod$/) {
@@ -91,6 +92,7 @@
 			if (/^(?:\Q$glue\E|\Q$glue1\E|\Q$glue2\E)\.pod$/) {
 				system('perldoc', @$switches, $file);
 				last OUTER;
+				}
 			}
 		}
 	}
diff -Naur Mac-Glue-1.23/scripts/gluemac.PL new/scripts/gluemac.PL
--- Mac-Glue-1.23/scripts/gluemac.PL	Tue Sep  2 03:37:04 2003
+++ new/scripts/gluemac.PL	Wed Mar  2 01:08:36 2005
@@ -37,6 +37,7 @@
 		where the app versions don't match)
 EOT
 	$Mac::Glue::Common::PROGOPTS = 'cr';
+	$Mac::Glue::Common::PROGUSEDOMAIN = 1;
 }
 
 use File::Spec::Functions;
@@ -53,14 +54,22 @@
 sub gluecheck {
 	require Mac::Glue;
 
+	my %seenapps;
 	my @paths;
-	opendir my $dh, $MACGLUEDIR or die $!;
+	
+	for my $gluedir (domain_dirs domain_read) {
+		opendir my $dh, $gluedir or die $!;
 	for my $name (readdir $dh) {
 		next if $name =~ /\.pod$/;
-		next unless -f catfile($MACGLUEDIR, $name);
+			next unless -f catfile($gluedir, $name);
 		next if $name eq 'FontSyncScripting'; # something's wrong ... ?
 
 		my $glue = new Mac::Glue $name;
+			
+			# only look at the visible (first seen) glues
+			next if exists $seenapps{$glue->{APPNAME}};
+			$seenapps{$glue->{APPNAME}} = 1;
+								
 		if ($opts->{c}) {
 			eval {
 				$glue->{TIMEOUT} = 10;
@@ -82,6 +91,7 @@
 			} or warn "Error for $name: $@";
 		} elsif ($opts->{r}) {
 			push @paths, _get_path($glue);
+			}
 		}
 	}
 	glue($opts, \@paths) if @paths && $opts->{r};
diff -Naur Mac-Glue-1.23/scripts/gluescriptadds.PL new/scripts/gluescriptadds.PL
--- Mac-Glue-1.23/scripts/gluescriptadds.PL	Sat May  3 21:09:47 2003
+++ new/scripts/gluescriptadds.PL	Wed Mar  2 01:08:36 2005
@@ -32,6 +32,7 @@
 Read the documentation for created glues with the gluedoc program (for
 additions, use the -a switch).
 EOT
+	$Mac::Glue::Common::PROGUSEDOMAIN = 1;
 }
 
 use File::Find;
diff -Naur Mac-Glue-1.23/scripts/show_glue_pods new/scripts/show_glue_pods
--- Mac-Glue-1.23/scripts/show_glue_pods	Wed Aug 27 22:48:07 2003
+++ new/scripts/show_glue_pods	Wed Mar  2 01:08:36 2005
@@ -1,18 +1,21 @@
 #!perl -w
 use File::Spec::Functions;
 use Mac::Glue;
+use Mac::Glue::Common;
 use Mac::InternetConfig;
 $app = MacPerl::Ask('Enter the name of a glue:') or exit;
 ($app1 = $app) =~ tr/ /_/;
 ($app2 = $app) =~ tr/_/ /;
 
-OUTER: for my $d (map { catfile($Mac::Glue::MACGLUEDIR, $_) } '', 'dialects', 'additions') {
+OUTER: for my $gluedir (domain_dirs domain_read) {
+	for my $d (map { catfile($gluedir, $_) } '', 'dialects', 'additions') {
 	for ($app, $app1, $app2) {
 		my $f = catfile($d, "$_.pod");
 		if (-e $f) {
 			$file = $f;
 			$file =~ tr|:|/|;
 			last OUTER;
+			}
 		}
 	}
 }
