Searching for files with Finder - name contains strings from list

That’s why I mentioned it – but the difference was slight, and my test folder very basic. I guess what I was really saying was that I was surprised there wasn’t a significant difference the other way around, though.

FWIW, changing the repeat loop slightly to use grep will deal with hamburgers and Berliners:

repeat with aString in searchStrings
	set aString to (current application's NSRegularExpression's escapedPatternForString:aString) -- escape any significant characters
	set end of thePreds to (current application's NSPredicate's predicateWithFormat_("self matches %@", "(?i).*" & aString & "[ _. ].+"))
end repeat

That should theoretically slow it down a smidge, but I can’t see any difference here.

You know, there’s an app for that :wink:

Probably, but I’m always nervous about the risk of the Spotlight database being wrong when there’s not a lot time to be gained. I just changed my test folder from a handful of files to 500-odd, and the sed time only rose from 0.01 to 0.053 seconds (whereas the ASObjC time went to 0.034).

So much for theory. My test on a larger number of files shows the regex version is actually quicker.

I wrote a small handler earlier, that can be used without well, it actually loads, but from a 2.3 style script library.

I haven’t made terminology available yet, since I try to compose libraries.

debug timing.scptd

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

on millisec()
	tell current application's NSDate's alloc()'s init() to return ((its timeIntervalSince1970()) * 1000)
	
end millisec

Here is example usage:

use AppleScript version "2.3"
use scripting additions

use dbg : script "debug_timing"

set a to dbg's millisec()


set b to ((dbg's millisec()) - a)

log b
-- > 0.371826171875

I agree with you, you also have the risk of the spotlight index being corrupted, rendering the solution unusable. :confused:

Such a solution with mdfind would probably be better when the sought items are spread over several folders, or if other file attributes are forming the search criteria, (than the filenames).

You’re doing more work than you have to there – use the class method:

current application’s NSDate’s timeIntervalSinceReferenceDate() *1000

Hello Shane.

Sure.

Thanks. :slight_smile:

Hey Nigel,

Shane undoubtedly realized that line was an extraneous leftover from the development process and removed it. (I’ve since elided it from the original.)

I used a test folder with 500 files in it, and in my tests my script is consistently a trifle faster than your second effort when timed in Smile with chrono.

But we’re only talking about 2 or 3 thousands of a second.

The why of that is less than obvious, but the difference is so small I’m not going to futz with it anymore.

Hey Shane,

In Yosemite is there an initial load delay for ASObjC like there is in Mavericks?

I’m holding off on installing Y-bugly until Apple fixes some of the more egregious problems.

Yes – frameworks still aren’t loaded until they are needed.

It’s probably worth adding that it’s per application. So if you are running scripts from FastScripts, for example, the delay will happen the first time the framework is loaded – from then on, there’ll be no delay when any scripts that use that framework are run from FastScripts.