How to Spotlight
How to Spotlight
- Subject: How to Spotlight
- From: Luther Fuller <email@hidden>
- Date: Sun, 11 Feb 2007 13:53:16 -0600
On 31 Jan, I complained "Why Spotlight?". I tried using mdfind ... it
returns results, but there's no place to display them, so it's
useless. This morning, I opened a Smart Folder (really a .savedSearch
document) with "Property List Editor.app" ... and immediately knew
what to do, even if it didn't work. It worked! Here's an example
script to search the frontmost folder for pdf files that contain
words beginning with all entered keywords. It must be saved as an
application bundle to work properly.
The file ...:Contents:Resources:display.savedSearch is a new Smart
Folder. Just make it and put it in the right place. Don't worry about
what it contains. Copy, compile, have fun!
property oldKeys : ""
on run
tell application "Finder"
try
set frontDir to (target of window index 1) as alias
on error
return
end try
((path to me) as text) & "Contents:Resources:display.savedSearch"
set searchDisplay to the result as alias
"Find pdf documents in \"" & (name of frontDir) & "\" for all key
words beginning ..."
display dialog the result default answer oldKeys buttons {"Cancel",
"Find"} cancel button 1 default button 2
set oldKeys to (text returned of the result)
set keyList to words of oldKeys as list
end tell
--
set queryStr to "(kMDItemContentTypeTree = 'com.adobe.pdf')" as
Unicode text
repeat with keyWord in keyList
" && (kMDItemTextContent = '" & keyWord & "*'wc)"
set queryStr to queryStr & the result as Unicode text
end repeat
--
set searchPath to POSIX path of frontDir
set displayPath to searchDisplay as text
tell application "System Events" to set searchRecord to value of
property list file the result
{|CurrentFolderPath|:{searchPath}, |FXScopeArrayOfPaths|:
{searchPath}} & |SearchCriteria| of searchRecord
set |SearchCriteria| of searchRecord to the result
set searchRecord to {|RawQuery|:queryStr} & searchRecord
tell application "System Events" to set value of property list file
displayPath to searchRecord
tell application "Finder" to open searchDisplay
end run
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/mailman//archives/applescript-users
This email sent to email@hidden