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: Chris Espinosa <email@hidden>
- Date: Wed, 17 Mar 2004 13:10:39 -0800
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.