Re: Madness & frustration... What is a file? What is a Path?
Re: Madness & frustration... What is a file? What is a Path?
- Subject: Re: Madness & frustration... What is a file? What is a Path?
- From: Walter Ian Kaye <email@hidden>
- Date: Wed, 12 May 2004 09:32:42 -0700
At 10:14a -0400 05/12/2004, Cliff Pruitt didst inscribe upon an
electronic papyrus:
Sigh... OK, can any of you brilliant AS veterans possibly explain
the difference between files, references to files, aliases & paths?
While standing on one foot? :-)
A path is not a file; it's just a string which can be coerced to a
file, but you should avoid relying on any automatic coercion and
always make an explicit file reference.
file "foo:bar:baz"
alias "foo:bar:baz"
POSIX file "/tmp/foo" --will decompile to Mac style
POSIX file ("" & "/tmp/foo") --avoids decompilation
POSIX path of alias "foo:bar:baz"
"foo:bar:baz" as file specification --aka FSSpec
"foo:bar:baz" as <<class furl>> --with real chevrons
NB: While 'alias "foo:bar:baz"' _looks_ like a path string with a
keyword prepended, behind the scenes it is actually a real alias
structure, containing exactly the same data as the 'alis' resource
inside a Finder alias file. (You wouldn't want all that binary code
cluttering up your script editor, so it's invisible -- but it exists
just the same.)
Also, how do you work with POSIX (/) and Mac styled (:) path delimiters?
Separately, of course. ;)
Which is the "correct" delimiter?
The one with the corresponding context:
POSIX file some_posix_path
file some_mac_path
They seem to both be used but under different circumstances.
Yes. If you're going to talk to the Unix shell, you'll need to use
POSIX paths since Unix doesn't know any other format. You may also
choose to use a POSIX format for convenience (such as creating a file
in /tmp; see above).
What is the easiest & most straightforward way to locate a file &
work with it?
Depends. ;) Well, it depends on whether the file is in a standard location.
Ask a general question, get a general answer...
How do you take a path and append text & then use it as a path to
get to a file. For example, this never seems to work for me:
Tell Application "Whatever"
set homePath to path to home folder
You want 'path to current user folder' or 'path to "cusr"'.
set theFile to homePath & ":Documents:Folder 1:Folder 2:file.txt"
The 'path to' command returns an alias object. You cannot append a
text object to an alias object; if you try, you get a list of those
two dissimilar items.
You have to coerce the alias to a string before appending another string.
(There is no automatic coercion of the object on the left of the
operand; only of the object on the right.)
Also, when you coerce a folder alias to a string, it will already
have the trailing colon; you don't want to get "::" because that will
behave the same as "../" in Unix and go relative to the parent folder.
open theFile
End Tell
It seems like it should be straightforward but for some reason it
never works the way I think it will...
set homePath to (path to current user folder) as string
set filePath to homePath & "Documents:Folder 1:Folder 2:file.txt"
tell application "Whatever" to open alias filePath --or 'file filePath'
Anyway, I'm just trying to get a good handle on this so any insight
you guys can provide would be great. I'm sure I can return the
favor someday.
Hope this wasn't too much info. :)
-Walter
_______________________________________________
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.