On Sep 7, 2010, at 5:35 PM, Shane Stanley wrote: On 8/9/10 3:51 AM, "Luther Fuller" < email@hidden> wrote: I have a script that I run from time to time. It takes about 60 sec to
complete.
If I immediately run it again, the script completes in 8 sec.
Why?
That's hard to know without knowing what handlerCalledByMe() is doing. For example, if it's reading a large file, the file could be cached. If it's talking to System Events, it may need to launch the app the first time. But if you're worried about speed, using Finder properties to parse a path rather than something like text item delimiters seems a poor choice.
handlerCalledByMe ... 1. Asks the user for a label color 2. Recursively scans a folder for alias files with a particular name 3. If it finds one, it scans the original item, always a folder, for files having the chosen color. 4. If a file with the chosen color exists, the folder is opened. The core code is tell application "Finder"
set linkedFolder to original item of (alias file linkName of folder subFolder) if exists (some document file of entire contents of linkedFolder whose label index is labelIndex) then
Could the culprit be 'entire contents'?
Not wanting a 60 second delay in executing a simple script is not exactly worrying about speed, and the difference in speed between the finder parsing a single path one time and any other method would be imperceptible.
And while the problem may be in the handler, it may also be in the application containing the handler. Is that a script? Does have a run handler that executes when opened? Is it stay open, so it doesn't have to launch on subsequent runs?
The hostAppl has a run handler, but it is avoided by using 'launch'. It is not stay-open. Also if memory on the mac is tight that could account for the inconsistent timing too. What if you don't run it again immediately, what if you do other things with other aps, then come back to it?
Pause ... It ran in 8 sec. Writing this message did not cause it to slow. I launched a whole bunch of applications, then quit them. Tried again ... 28 sec Immediately tried again ... 8 sec.
You may be onto something.
|