After that we can retrieve the file specification
of any item, barring
some weird errors that I couldn't fix. But file specs are simple
objects
without any real info other than a path. You can then use info for
{file
specification} to retrieve a record of some of the Finder info for
a
file. Unfortunately, info for folders is different than info for files,
and
if you try to retrieve an record item with the wrong key, you get an
error
that you need to catch.
There is one more problem with the file info record. It has a folder
attribute that is true if the file is a folder -- and an Application
Frame-
work is a folder, though that's not the problem I was referring to. If
you
try to retrieve the folder attribute in a tell application "Finder"
block, AppleScript asks the Finder to get the folder of file info which
is an
error. I couldn't get around this by somehow signifying that folder
is an attribute. So I made it into a subroutine:
on addIsFolderAttribute(l_record) if (class of l_record is record) then -- Add isFolder attribute so we can refer to it instead of folder set l_return to l_record & {isFolder:(folder of l_record)} -- Add dummy file type if there is none try file type of l_return on error l_error set l_return to l_return & {file type:false} end try -- Check to see if this an application, in which case treat it as a non-folder if (name of l_return ends with ".app") then set isFolder of l_return to false end if return l_return else return l_record end if end addIsFolderAttribute
The above simple handler does some useful things. First it copies the
folder
attribute to isFolder, so I can query it from a tell Finder block. It
also
adds file type to folder file info records, so I don't have to
test
separately for that. And it sets isFolder to false if this is
an
Application Framework. The only problem here is that I can only tell
that
this is an Application Framework because it ends with ".app", none of
the
file info record attributes give me a clue.
So with file specs and file info records, I can do almost everything
that I
could do with Finder objects. And now I can copy Application
Frameworks.
At this point I hope that Synchronize Folder works with just every file
type
and is generic enough to do the job. But only more testing will tell.
One
thing I want to add is specifying the time error for date comparisons.
That
way if the modification dates differ by only a few seconds it won't
copy the
file. For some reason all the files I Finder copied have a modification
date
a couple of seconds after the original files. I guess Finder copy is
not
quite right all the time, which is annoying if you're comparing exact
times.
This AppleScript is still a long way away from being good enough to
release,
but I've made a lot of progress this week. From nothing to something
that
should work fine as is, though without a lot of bells and whistles. I
hear
that Mac OS X 10.1 has better AppleScript support and perhaps the
Application
Framework issue that I encountered is fixed there (though it's probably
not
a bug). I'll have a chance to test it out when I install it this
weekend, as
my 10.1 upgrade package finally arrived. Hooray!
|