• 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: Is there a way to speed this up?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is there a way to speed this up?


  • Subject: Re: Is there a way to speed this up?
  • From: Brian Christmas <email@hidden>
  • Date: Wed, 05 Oct 2016 13:58:24 +1100

Thanks Shane

Running fine now, down to 15 seconds, from 28. I don’t think my clients will mind waiting about a minute for searching i million + items.

Regards

Santa

use AppleScript version "2.4"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property mailManagerDesktopFolderPath : ""
property searchString : ""
property theFoundList : {}
property paragraphCount : 0
set my searchString to "ozsanta" as text
set my mailManagerDesktopFolderPath to ((path to desktop) & "Mail Manager Folder" as text)
my gatherInfo()

on gatherInfo()
with timeout of 1000 seconds
set theStart to current date
set my paragraphCount to 0
ignoring case
tell application "Finder"
set my theFoundList to {} as list
set theDataList to (folders of folder mailManagerDesktopFolderPath whose name starts with "Mail Data") as list
repeat with eachFolder in theDataList
set fileList to files of eachFolder as alias list
repeat with eachFile in fileList
set theParas to ""
set theString to (current application's NSString's stringWithContentsOfFile:(POSIX path of eachFile) encoding:(current application's NSUTF8StringEncoding) |error|:(missing value))
-- make sure match string is regex "safe"
set thePattern to (current application's NSRegularExpression's escapedPatternForString:(my searchString)) as text
-- put a unique character at start of matching lines
try
set theString to (theString's stringByReplacingOccurrencesOfString:(".*" & thePattern & ".*") withString:"πŸ˜€$0" options:(current application's NSRegularExpressionSearch) range:{0, theString's |length|()})
-- delete all lines that don't start with the unique character
set theString to (theString's stringByReplacingOccurrencesOfString:"(?m)^[^πŸ˜€].*(\\n|\\r)*" withString:"" options:(current application's NSRegularExpressionSearch) range:{0, theString's |length|()})
-- delete the unique character at the beginning of lines
set theString to (theString's stringByReplacingOccurrencesOfString:"(?m)^πŸ˜€" withString:"" options:(current application's NSRegularExpressionSearch) range:{0, theString's |length|()})
-- strip trailing returns/linefeeds
set theString to (theString's stringByTrimmingCharactersInSet:(current application's NSCharacterSet's whitespaceAndNewlineCharacterSet()))
-- convert to paras of AS text
set theParas to paragraphs of (theString as text)
end try
if theParas β‰  "" then
repeat with eachPara in theParas
set end of my theFoundList to eachPara as list
end repeat
end if
end repeat
end repeat
end tell
end ignoring
tell application "System Events" to display dialog (current date) - theStart & " seconds to process" & return & return & (count of my theFoundList) & " matches" as text giving up after 600
set temp to item 1 of my theFoundList as text
set {tild, my text item delimiters} to {AppleScript's text item delimiters, ","}
set storedReference to text item 1 of temp as text
set storedEmailAddress to text item 2 of temp as text
set storedEmailName to text item 3 of temp as text
set AppleScript's text item delimiters to tild
tell application "System Events" to display dialog storedReference & return & storedEmailAddress & return & storedEmailName
end timeout
end gatherInfo
 

And what, you ask, was the beginning of it all?
And it is this......
Existence that multiplied itself
For sheer delight of being
And plunged with numberless trillions of forms
So that it might
find
itself
innumerably

Sri Aurobindo



 _______________________________________________
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: Is there a way to speed this up? (From: has <email@hidden>)
 >Re: Is there a way to speed this up? (From: Brian Christmas <email@hidden>)
 >Re: Is there a way to speed this up? (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: Saving in photoshop CS6 with option
  • Next by Date: Re: stringWithContentsOfURL works when it's a script, not when it's an app
  • Previous by thread: Re: Is there a way to speed this up?
  • Next by thread: stringWithContentsOfURL works when it's a script, not when it's an app
  • Index(es):
    • Date
    • Thread