Hello Marion,
On Apr 16, 2013, at 01:24, Marion Dickten < email@hidden> wrote: Why should I avoid telling the Finder? Yvan Koenig wrote "I always do my best to never trigger the Finder in scripts"
Well. That's Yvan's particular prejudice. Which is not to say it is without merit. You need to know what you're doing with the Finder to avoid its pitfalls.
For instance you never want to use entire contents of a folder if there are many items in it. Your system will CRAWL - perhaps for minutes at a time - or even MANY minutes.
In contrast to Yvan I personally dislike System Events, because it intermittently takes 3 or more seconds to launch on my machine. It's a little 800K app, and it can take 3+ seconds to launch???? This used to not be much of an issue, because it would stay resident once launched the first time. But now with auto-quitting it is completely unpredictable.
(To tell an app called "System Events" to give me the files contained in a folder seems to me anything but straightforward, files not having to do anything with any event.)
Well, I'm guessing it's been a while since you've done much scripting, because System Events came along YEARS ago to try to overcome some of the deficiencies of the Finder and to add more functionality to Applescript.
I just virtually locked up my system for 41 seconds by doing this:
-------------------------------------------------------------------------------------------
set FL to alias ((path to downloads folder as text) & "•• { Downloaders } ••:")
tell application "Finder" entire contents of FL end tell
--> 3662 items were found as a list of Finder references.
-------------------------------------------------------------------------------------------
By contrast a small change dropped the runtime to 3.5 seconds:
-------------------------------------------------------------------------------------------
set FL to alias ((path to downloads folder as text) & "•• { Downloaders } ••:")
tell application "Finder" set _list to entire contents of FL as alias list end tell
--> 3662 items were found as an alias list.
-------------------------------------------------------------------------------------------
So while the Finder can be a real problem I usually find ways to work with or around it.
-- Best Regards, Chris
|