Re: Problems scripting the Finder with system
Re: Problems scripting the Finder with system
- Subject: Re: Problems scripting the Finder with system
- From: email@hidden
- Date: Sat, 6 Jan 2001 19:21:34 -0500
On Fri, 05 Jan 2001 21:00:49 -0700, 9.0.4
"John McElwain" <email@hidden> asked,
>
My script basically recursively processes a folder filled with aliases.
>
gets an ID from the file comments, gets the modification date from the
>
original, checks the mod. date against the date and time in an associated
>
FileMaker record, and if required, updates the FM record.
>
>
If I process a folder containing 160 file, it takes about 60 sec with System
>
9.0. To process the same folder under 9.0.4, takes 5-8 mins [Running the
>
same script, one time after another, it took 4:50, 8:10, 7:15, 7:30 and 4:40
>
mins:sec] This is the same script, same extensions, without recompiling.
>
as the # of files approaches 1000, I start to see more problems with the
>
script, e.g. timeout errors from the Finder.
I can't explain the difference in speeds between 9.0 and 9.0.1, but I can give
some general advice.
1. Sending messages (Apple Events) between applications is phenomenally slow,
compared to executing script commands. Its thousands of times slower. So you
want to do as much as possible with a few Apple Events as possible. If you can
get the Finder to do everything you want in one message, do that.
tell application "Finder" to set visible of (every file whose name begins
with "Foo") to true
(untested code). Unfortunately, when dealing with numeric and date properties
of files, the Finder doesn't deal with filter reference correctly in some cases.
If you can't get a filter clause to do everything you want in one fell swoop,
try getting the whole list of files from the Finder, and then working with that
list, rather than asking the Finder for the files one at a time.
2. You may be sending more messages than you expected. Turn on the Event Log in
Script Editor and see what is being actually sent. You may be re-counting the
files in a folder, or re-retrieving the name of a file more than once. If you
spot things like this, get the data once and store it in a variable in the
script.
3. You may be able to use a scripting addition instead of the Finder for some
types of file manipulation. Calling a scripting addition in your own
application is much faster than calling a handler in another application. But
beware of the Standard Additions' "info for" command, when called on a folder.
Because it calculates the size of the folder, it can take many seconds to add up
all the files in a big folder. In that case, Akua Sweets has a similar command,
"basic info for", that doesn't get the time-consuming data.
--
Scott Norton Phone: +1-703-299-1656
DTI Associates, Inc. Fax: +1-703-706-0476
2920 South Glebe Road Internet: email@hidden
Arlington, VA 22206-2768 or email@hidden