Re: How many files could a Finder find if a Finder could find files?
Re: How many files could a Finder find if a Finder could find files?
- Subject: Re: How many files could a Finder find if a Finder could find files?
- From: Nelson Byrne <email@hidden>
- Date: Wed, 17 Mar 2004 13:43:29 -0800
Thanks for your explanation. I kinda guessed something like that, why I
put those "update"s in there. They don't seem to fix the problem, as
you see. I guess I needed a new parameter: "update with IMeanIt."
It's not *quite* true that "...anything you do to one icon (move, drag
to trash) will cause the Finder to synch up, and the other icon will
disappear." You can drag either icon around on the Desktop.
Also, whereas I think I understand your "behind the Finder's back"
comment, I'm puzzled by what you mean when you say: "Files placed in a
directory by the Finder, or there when the Finder first opened the
window, are noticed by the script and cause the error." I only saw the
problem when I created them BTFB.
Thanks again,
Nelson
PS I get the impression that System Events is getting to be the tool of
choice for file work. Is that right?
On Mar 17, 2004, at 1:10 PM, Chris Espinosa wrote:
>
On Mar 17, 2004, at 12:21 PM, Nelson Byrne wrote:
>
>
> The answer is two, max, given that they have the same name and path.
>
>
>
> Before running this for the first time, go to Terminal and type
>
> rm -f Desktop/aaa ; touch Desktop/aaa
>
> This will create a zero length file on your desktop. Now paste the
>
> following script into Script Editor and run it.
>
> ================
>
> property FPath : path to desktop
>
> property FName : "aaa"
>
>
>
> tell application "Finder"
>
> update FPath
>
> get (every file of FPath where name of it is FName)
>
> make new file at FPath with properties {name:FName}
>
> get (every file of FPath where name of it is FName)
>
> update FPath
>
> end tell
>
> ================
>
>
>
> Now you have a pair of files on your desktop, each named aaa and with
>
> their icons overlaying one another. They can be moved around
>
> separately. A second execution bombs off at the "make new file."
>
>
>
> The Event Log reveals that on the first execution the "get every
>
> file" at the top shows just the one file. Then Finder makes another
>
> one anyway with the exact same name and path, and the "get every
>
> file" at the bottom then returns a list of two items, each the same.
>
>
>
> Running it as an app doesn't make this happen, though.
>
>
>
> Another oddity is that Finder does not think aaa "exists" (the first
>
> time through (when it's been made by Terminal) even though "get every
>
> file" shows it. This in fact is how I stumbled onto this, because it
>
> made a script I'm working on go down the wrong rabbit hole. I know,
>
> just don't count on "exists" working, instead "get every file" and
>
> check for a non-zero length of the returned list. Maybe we'd better
>
> check on *positive* length, come to think of it, no? You just never
>
> know.
>
>
>
> I'm running 10.3.3
>
>
>
> Comments very welcome.
>
>
This appears to be a Finder scripting bug in that it fails to notice
>
the first file, and creates a second icon. There is only one file
>
(check list folder, ls, etc.) in the directory. Anything you do to
>
one icon (move, drag to trash) will cause the Finder to synch up, and
>
the other icon will disappear.
>
>
As far as I can tell this only happens with files written "behind the
>
Finder's back," i.e. by another process. Files placed in a directory
>
by the Finder, or there when the Finder first opened the window, are
>
noticed by the script and cause the error.
>
>
Use System Events, it works correctly:
>
>
property FName : "aaa"
>
>
tell application "System Events"
>
set FPath to desktop folder of user domain
>
get (every file of FPath where name of it is FName)
>
make new file at end of FPath with properties {name:FName}
>
get (every file of FPath where name of it is FName)
>
end tell
>
>
Chris
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.