In article <20011024200003-r01010800-e58cfee9-0921-0108@localhost>,
[EMAIL PROTECTED] (John Gruber) wrote:
> Is there an easy, reliable method to turn a Unix-style path into a
> Mac HFS-style path? For example, turning
>
> /Users/gruber/Documents/foo
>
> into
>
> Boot:Users:gruber:Documents:foo
>
> where "Boot" is the name of my startup disk.
>
> (Why? Because I want to write a script that executes an AppleScript
> using Mac OS X's osascript tool. I need to convert the file
> arguments into HFS-style paths, because osascript doesn't take
> command line arguments and AppleScript doesn't understand Unix-style
> paths.)
There are some cases that you really can't map a unix path to a Mac HFS
path. The best example is when you have two volumes with the same volume
name; the unix path is unique (e.g., /Volumes/foo and /Volumes/foo1) but
the Mac HFS path is not. Also NFS paths have volume names like <nfs -1000>
, and I'm not sure if this is fully compatible.
But short of these issues, it isn't hard to write some C code to take a
path, compute the equivalent FSSpec (from CoreFoundation documentation)
and then walk the tree to get the Mac HFS path (from Inside Macintosh). I
can send you a code snippet if you're interested. (And it should be easy
to make this code into an extension, if one is so inclined).
But for the AppleScript case, turns out there is an easier solution,
available in AppleScript 1.8 (part of the latest developer tools):
set x to "/tmp/foo"
get POSIX file x
results in:
file "MacOSX:private:tmp:foo"
and:
set x to "MacOS9:System Folder"
get POSIX path of x
results in:
"/Volumes/MacOS9/System Folder"
A round of applause for the AppleScript team...
--------------------------------------------------------------------------
Edward Moy
Apple Computer, Inc.
[EMAIL PROTECTED]
(This message is from me as a reader of this list, and not a statement
from Apple.)