Hi!- glad to be a new member and eager to improve my applescript skills…
Since I do not like spotlight much I would like to build an Applescript front end to the ‘locate’ command. By borrowing code from other people’s scripts i have produced two almost identical scripts; one opens its reults in an applescrpt dialog and the other in a textedit window. Neither are ideal.
What I’d like to do is display the results in a single Finder window. This would allow a user much more flexibility in how they handle the results. Any help with this would be greatly appreciated.
To test the scripts it will be necessary to build your locate db. Do so by running the following in Terminal: /usr/libexec/locate.updatedb
If you get permissions errors then authenticate as a super-user before running the above command by typng:
sudo -s
into a new Terminal window (then entering an admin password)
It would also be great if a button for “Update Locate DB” (to invoke above command) could also be added to the dialog.
tremendous gratitude for any help making this applescript app better.
LOCATE SCRIPT
property theCommand : ""
repeat while theCommand is ""
display dialog "What do you wish to locate?:" default answer theCommand
set theCommand to text returned of result
end repeat
try
do shell script "locate -i " & quoted form of theCommand
display dialog result
on error errorMsg number errorNum
display alert "Error " & errorNum message errorMsg buttons "Cancel" default button 1
end try
LOCATE SCRPIT 2 (TextEdit version)
property theCommand : ""
repeat while theCommand is ""
display dialog "What do you wish to locate?:" default answer theCommand
set theCommand to text returned of result
end repeat
try
do shell script "locate -i " & quoted form of theCommand & "| open -f -a /Applications/TextEdit.app"
on error errorMsg number errorNum
display alert "Error " & errorNum message errorMsg buttons "Cancel" default button 1
end try
Hi,
I guess displaying the results in a Finder window is impossible, but why not use Safari?
set searchword to "invoice"
set command to "locate -i " & quoted form of searchword
set founditems to paragraphs of (do shell script command)
set htmlcont to ""
repeat with founditem in founditems
set itemurl to "file://" & founditem
set htmlitemurl to "<p><a href=\"" & itemurl & "\">" & itemurl & "</></p>"
set htmlcont to htmlcont & htmlitemurl
end repeat
set htmltop to "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">
<head>
<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />
<title>Untitled</title>
</head>
<body>"
set htmlbottom to "</body></html>"
set htmlfilepath to ((path to desktop) as text) & "locate.html"
try
set htmlfile to open for access htmlfilepath with write permission
write htmltop to htmlfile as «class utf8»
write htmlcont to htmlfile as «class utf8»
write htmlbotton to htmlfile as «class utf8»
close access htmlfile
on error
try
close access htmlfile
end try
end try
tell application "Safari"
activate
open (htmlfilepath as alias)
end tell
wow - thats very nice! 
really really nice…
… but it is still not quite as elegant as the Finder solution. When you say you guess displaying the results in a Finder window would be impossible do you mean it is impossible?
right-clicking on a highlighted file path in Terminal or TextEdit offers a ‘Reveal in Finder’ in the menu items. could this somehow be leveraged?
your safari variation is certainly the best yet altho it has a quirk or two. Safari will always insist upon playing an mp3 or avi or mp4 or any codec QT recognises. Could this behaviour be altered so that, for example, an mp3 would always open in VLC?
these are but quibbling details and your work is delightful. until such times as i can get my Finder dream realised the Safari solution will keep me happy. thanks for your efforts 
p.s. is this thread connected to the pursuit of my Finder dream?
http://macscripter.net/viewtopic.php?id=15114
Hi Dorian,
Until you mentioned it I did not know the locate command, but found it to be very useful in my daily work.
So I quickly wrote a convenient Cocoa application, which displays the locate results in a table view and reveals them in the Finder once you click on a row:
Screenshot ¢ Locator app
It currently only runs on Mac OS X 10.6 Snow Leopard (just because I used an Xcode 3.2 project template).
If you are interested you can download both the app and the Xcode project here:
Download Locator (ZIP archive, ca. 2.5 MB)
Best regards from cloudy and cold Berlin,
Martin
wow! amazing Martin. I neglected this thread for way too long! thanks for the christmas present 
have u uploaded it to a site or r u gonna develop it further? you could even make it shareware or donationware!
can i suggest maybe in preferences or as a menu option or just a button in the UI to ‘Update locate database’ or something to that effect.
spotlight bugs me in so many ways (esp keeping external HD’s from spinning down by continuously indexing them) and for me the locate command and now Locator.app is better than spotlight so long as one does not care about searching file metadata.
this app is very nice - pls take it further - i’ll help any way i can
Hey Martin,
I don’t know if you have had a chance to play around with AppleScriptObjC so here is an example based on your Locator app.
It is named “Locater” on purpose so not to conflict with your version.
Merry Christmas and Happy New Year!
Craig
Download zip file