Re: Path to a file
Re: Path to a file
- Subject: Re: Path to a file
- From: Chris Nebel <email@hidden>
- Date: Sat, 07 Apr 2001 13:06:56 -0700
- Organization: Apple Computer, Inc.
giZm0 wrote:
>
Hi, I am trying to get a path to a file as string.
>
My script looks like that:
>
>
Tell app "Finder"
>
set lalocation to (path to (file "mp3list.txt" of system folder)) as string
>
End tell
>
>
But I just keep getting error messages when I run the script...
Your desire to be path-independent is commendable, but you misunderstood what
"path to" actually does. "Path to" is designed to give you the locations of
various interesting folders -- the system folder, the control panels folder,
etc. -- so you don't have to know exactly where they are in the file system.
It does *not* get the paths of arbitrary files -- for that, you can just
convert the file object into a string using "as string".
That said, there are a couple of ways to solve your problem. One is to say:
tell application "Finder"
file "mp3list.txt" of the system folder as string
end
--> "Macintosh HD:System Folder:mp3list.txt"
Because "path to" is a scripting addition, not a Finder command, you don't
have to talk to the Finder, but instead do something like this:
path to system folder as string & "mp3list.txt"
--> "Macintosh HD:System Folder:mp3list.txt"
The deeper question is what are you going to use this path for? You may not
need a path at all, but simply a reference to the file. If you wanted to,
say, copy it to the desktop, all you'd need to do is this:
tell application "Finder"
duplicate file "mp3list.txt" of the system folder to the desktop --
look Ma, no path!
end
In general, if you're going to be manipulating the file using the Finder, then
it's best to just use Finder object references and leave paths out of it.
--Chris Nebel
AppleScript Engineering