[OS X TeX] How to make locate/spotlight search ~/Library/texmf

cfrees at imapmail.org cfrees at imapmail.org
Tue Aug 10 20:41:01 EDT 2010


On Tue 10th Aug, 2010 at 18:00, Alan Munn seems to have written:

> On Aug 10, 2010, at 5:04 PM, Dr. Clea F. Rees wrote:
>
>> On Tue 10th Aug, 2010 at 13:32, Michael Sharpe seems to have written:
>> 
>>> 
>>> On Aug 10, 2010, at 10:41 AM, Alan Munn wrote:
>>> 
>>>> On Aug 10, 2010, at 1:35 PM, Herbert Schulz wrote:
>>>> 
>>>>> 
>>>>> On Aug 10, 2010, at 12:16 PM, Alan Munn wrote:
>>>>> 
>>>>>> 
>>>>>> On Aug 10, 2010, at 12:51 PM, Herbert Schulz wrote:
>>>>>> 
>>>>>>> 
>>>>>>> On Aug 10, 2010, at 11:22 AM, Alan Munn wrote:
>>>>>>> 
>>>>>>>> Hi,  I can use the locate command in a Terminal to quickly find files 
>>>>>>>> in /usr/local/texlive.  However, it doesn't find files in 
>>>>>>>> ~/Library/texmf.  How do I make it do that?
>>>>>>>> 
>>>>>>> 
>>>>>>> I'd guess that the locate database won't contain anything in the Users 
>>>>>>> folder since that is private for each individual user. Perhaps there 
>>>>>>> is a way to ell it to build a personal database.
>>>>>>> 
>> There is. Or, at least, it can be done for GNU locate. I installed that
>> as glocate and then build both a general database and a personal
>> database. I then use locate to search the generic, system-wide database
>> which gets updated once a week, I think, or glocate to search both a
>> system-wide and personal database both of which are updated daily.
>> 
>> I can't remember why I did it this way so I'm not sure if you could do
>> the same with the default locate or not.
>> 
>> Let me know if you want further details.
>
> Hi Clea, yes, I would like to see the details if it's not too much trouble to 
> recreate them.

Remember that this was written for GNU locate. Unless you can adapt it,
you will need a copy of that programme. I installed it as 'glocate' so
that it doesn't conflict with Apple's locate.

GNU findutils will furnish locate (glocate) and updatedb (gupdatedb).

I run the following two scripts once a day (or, rather, my Mac runs
them :).

---gupdatedb.daily for the system-wide database---
#!/bin/sh -

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH

 	/usr/bin/sudo -u nobody /usr/local/bin/gupdatedb --prunepaths='/private/tmp /var/tmp /Network /Volumes' --output=/private/tmp/locatedb 2>&1 | sed -e '/Permission denied/d';
 	res=$?;
 	if [ "$res" != "0" ];
 	then
 		exit 1
 	fi
 	if [ -d /usr/local/var/locatedb ];
 	then
 		/bin/rm -f /usr/local/var/locatedb;
 		if [ "$res" != "0" ];
         	then
                 	exit 1
         	fi
 	fi
 	/bin/mv /private/tmp/locatedb /usr/local/var/locatedb;
 	if [ "$res" != "0" ];
         then
                 exit 1
         fi
 	chown nobody /usr/local/var/locatedb;
 	if [ "$res" != "0" ];
         then
                 exit 1
         fi
 	chgrp wheel /usr/local/var/locatedb;
 	if [ "$res" != "0" ];
         then
                 exit 1
         fi
 	chmod 444 /usr/local/var/locatedb;
 	exit $?
---end gupdatedb.daily---

---gupdatedb.users.daily calls custom script to update user-specific
databases---
#!/bin/sh -

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH

if [ -d "/Users" ];
then
 	lsusers=$(ls /Users | grep -v "Shared" | grep -v "Icon.*" | grep -v "\..*" | grep -v "SC" | grep -v "Info");
else
 	printf %b "Alert! /Users does not exist. Either this system has no human users or they are all homeless.\n";
 	exit 1
fi
for i in $lsusers
do
 	/usr/bin/sudo -u $i /usr/local/bin/gupdatedb.user;
 	exit $?
done
---end gupdatedb.users.daily---

---gupdatedb.user---
#!/bin/sh -

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH

pwy=$(whoami)
if [ "$pwy" != "" ];
then
 	if [ -d "/Users/$pwy/Library/Indexes" ] && [ -w "/Users/$pwy/Library/Indexes" ];
 	then
 		out="/Users/$pwy/Library/Indexes";
 	else
 		out="/private/tmp";
 	fi
 	if [ -w "$out/locatedb.$pwy" ];
 	then
 		targdb="$out/locatedb.$pwy"
 	else
 		if [ -e "$out/locatedb.$pwy" ];
 		then
 			printf %b "Error: target database ($out/locatedb.$pwy) not writable.\n";
 			exit 1
 		else
 			/usr/bin/touch $out/locatedb.$pwy
 			if [ "$?" != "0" ];
 			then
 				printf %b "Error: could not create target database ($out/$locatedb.$pwy).\n";
 				exit 1
 			else
 				targetdb="$out/locatedb.$pwy"
 			fi
 		fi
 	fi
else
 	printf %b "Error: cannot figure out who I am.\n";
 	exit 1
fi
if [ -d "/Users/$pwy/tmp" ];
then
 	PRUNEPATHS="/Users/$pwy/tmp";
 	export PRUNEPATHS
fi
printf %b "Running gupdatedb for user $pwy and output database $targdb.\n";
/usr/bin/nice /usr/local/bin/gupdatedb --localpaths="/Users/$pwy/" --output="$targdb";
exit $?
---end gupdatedb.user---

Note that these scripts were not written for public use and I haven't
edited them so be aware that they may well trade on aspects of my setup
and need tweaking for use elsewhere!

Hope this is of some interest/use.

Good luck,
Clea



More information about the MacOSX-TeX mailing list