• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Mail Search surrogate
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mail Search surrogate


  • Subject: Re: Mail Search surrogate
  • From: Jon Pugh <email@hidden>
  • Date: Thu, 9 Apr 2009 10:32:25 -0700

At 10:24 AM -0700 4/9/09, Gil Dawson wrote:
>>Google "spotlight mdfind".
>
>I'll give it a try.

Here's a sample script, which I use in BBEdit.  I have a variety of them, hardcoded for different project directory trees so I can prune my results appropriately, so feel free to munge this as needed.

The majority of this script is oriented toward getting a list of results from Spotlight and then having BBEdit search those files and produce a browser of hits.  With any luck you could do something similar in Mail.

Jon


-- get and remember the selected string
property pLastQuery : ""
tell application "BBEdit"
	set bbpath to file of document 1 as string
	try
		set s to contents of selection
	on error number -1728
		set s to ""
	end try
end tell
-- allow you to select an entire line and ignore the return character
if length of s > 1 and last character of s = return then
	set s to characters 1 thru -2 of s as string
end if
if s ‚ "" then
	set pLastQuery to s
else
	-- no selection, so ask for a string
	set pLastQuery to text returned of (display dialog "Find what?" default answer pLastQuery)
end if
set ftext to do shell script "mdfind \"" & pLastQuery & "\"" -- & " -onlyin /Work/" -- can use a directory to limit the search
-- turn the textual list of posix file paths into an AppleScript list of file references
set flist to {}
set fparas to paragraphs of ftext
repeat with f in fparas
	try
		set pf to POSIX file f
		copy pf to end of flist
	end try
end repeat
-- have BBEdit search only those files for the original text
tell application "BBEdit"
	find pLastQuery searching in flist options {search mode:literal, case sensitive:false, match words:false, extend selection:false}
end tell
-- now have a find window open in BBEdit without grepping extra files
 _______________________________________________
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/archives/applescript-users

This email sent to email@hidden

References: 
 >Re: Unicode Character in File Name (From: CYB <email@hidden>)
 >Re: Unicode Character in File Name (From: Luther Fuller <email@hidden>)
 >Re: Unicode Character in File Name (From: "Mark J. Reed" <email@hidden>)
 >Re: Unicode Character in File Name (From: Luther Fuller <email@hidden>)
 >Re: Unicode Character in File Name (From: Christopher Nebel <email@hidden>)
 >Re: Unicode Character in File Name (From: Luther Fuller <email@hidden>)
 >Re: Unicode Character in File Name (From: Christopher Nebel <email@hidden>)
 >Re: Unicode Character in File Name (From: "Mark J. Reed" <email@hidden>)
 >Re: Unicode Character in File Name (From: Doug McNutt <email@hidden>)
 >Mail Search surrogate (From: Gil Dawson <email@hidden>)
 >Re: Mail Search surrogate (From: Michelle Steiner <email@hidden>)
 >Re: Mail Search surrogate (From: Gil Dawson <email@hidden>)

  • Prev by Date: Re: Mail Search surrogate
  • Next by Date: Re: Mail Search surrogate
  • Previous by thread: Re: Mail Search surrogate
  • Next by thread: Re: Mail Search surrogate
  • Index(es):
    • Date
    • Thread