Re: Regarding the "info for" command
Re: Regarding the "info for" command
- Subject: Re: Regarding the "info for" command
- From: Bill Cheeseman <email@hidden>
- Date: Fri, 09 Feb 2001 16:35:47 -0500
on 2/9/01 3:51 PM, Robert Seckendorf at email@hidden wrote:
>
I was looking at some of the folder action scripts that are in the Scripting
>
Additions directory, but I don't need all the verbosity, and they seem to
>
rely on a osax called "label index" at least I think it's an osax.
Label Index is a property of the Finder's Item class, as shown in the
Finder's dictionary. In the scripts you were looking at, files or folders
are marked with a distinctive label simply as a convenient means to identify
those which meet a specific requirement.
>
In any
>
event, is there any way to check if a file is available merely by using the
>
"info for" command?
Yes. The AppleScript Language Guide explains the technique. If you seek Info
For a nonexistent file or folder, you will receive system error no. -43. If
you seek Info For a nonexistent disk, you will receive system error no. -35.
To prove this, run the following script:
try
set myPath to "<my disk>:foo"
info for alias myPath
on error errMsg number errNum
display dialog errMsg & space & errNum
end try
Unless I happened to guess your disk and file name exactly, you will be told
the operation generated error no. -35. If you substitute the name of your
startup disk for <my disk>, you will see error no. -43.
To use this fact in your script, you could, for example, use a handler that
returns true or false depending on whether a file exists, like so:
on fileExists(thePath)
try
info for alias thePath
return true
on error number -43
return false
end try
end
If you check for the existence of a folder in this manner, be warned that
the handler can take a long time to execute if the folder exists and it
contains a great many files.
However, none of this is likely to help you determine whether the files have
finished copying. The file may exist but not yet be complete. To test for
completeness, you need to test in a loop whether its file type is the type
you expect (e.g., "TEXT"), since in recent versions of the Mac OS the file
type of a file being copied or moved by the Finder has a special value until
the copy or move is complete. Several of the Folder Actions scripts you were
examining illustrate the technique.
-
Bill Cheeseman, Quechee, Vermont <
mailto:email@hidden>
The AppleScript Sourcebook
<
http://www.AppleScriptSourcebook.com/>
Vermont Recipes-A Cocoa Cookbook
<
http://www.stepwise.com/Articles/VermontRecipes/>