• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: More newbie queries: paths
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: More newbie queries: paths


  • Subject: Re: More newbie queries: paths
  • From: Christopher Nebel <email@hidden>
  • Date: Mon, 29 Apr 2002 12:15:52 -0700

On Sunday, April 28, 2002, at 06:24 PM, Michael Kelly wrote:

Thanks for the answers on my last question. I'm now banging my head in a
much more flexible environment! :)

My question has to do with paths in OS X. Since OS X is based on a Unix
kernel, shouldn't it use Unix paths? The "go-to" window in the Finder does.

But AppleScript seems only to like old, colon-delimited paths. This is
confusing and frustrating me to no end, partially because I've never fully
understood "classic" Macintosh path names to begin with. Am I wrong about
this?

AppleScript continues to use HFS-style colon-delimited paths in Mac OS X by design. An awful lot of scripts rely on coercing file objects to and from strings and then manipulating them by looking for colons. If AppleScript suddenly started using POSIX-style paths, all those scripts would break. We decided that would be a Bad Thing.

Now, if you want to use POSIX-style paths (and if you're going to use "do shell script" very much, you probably have to), there are a couple of new features that will help: POSIX path of a file object and the "POSIX file" pseudo-class. For example:

set x to file "HD:Users:me:thing.txt"
POSIX path of x --> "/Users/me/thing.txt"
POSIX file "/Users/me/thing.txt" --> file "HD:Users:me:thing.txt"

(The reason "POSIX file" isn't a real class will become apparent if you type that last line into Script Editor and compile it. It winds up creating a normal "file" object, which displays with an HFS path. A "POSIX file" object only exists long enough to become a "file" object.)

Here is what I currently think I know about Mac paths:

"Users:mkelly:" is equivalent to "/Users/mkelly/"
":Users:mkelly:" to "./Users/mkelly/"
"Users:mkelly::admin" to "/Users/mkelly/../admin/"

Am I terribly wrong somewhere?

Only a little bit. An HFS path that contains colons but doesn't start with one is considered to be absolute, i.e., it starts with a disk name. Therefore, "Users:mkelly" would actually be equivalent to "/mkelly" or "/Volumes/Users/mkelly", depending on whether your startup disk was named "Users" or not. More likely, you meant "HD:Users:mkelly" in the first example. [1]

Aside from that, you've got it right: a leading colon means a relative path, and two colons in a row means your parent. (Three colons in a row means your grandparent, four your great-grandparent, and so on. POSIX doesn't have a direct equivalent for that, though of course you can fake it by repeating "../" enough times.)

One final question: Does a trailing colon ever mean anything more than a
trailing slash does on Unix? (i.e., nothing if the path refers to a directory)

Not really. The trailing colon is merely a convention to indicate that a path is to a directory, not a file. It's not required for anything, though a lot of scripts rely on looking for it because AppleScript is polite and always puts it on if it's appropriate.


--Chris Nebel
AppleScript Engineering

[1] In fact, there's an additional wrinkle. The POSIX path conversion AppleScript uses has some fall-back behavior that makes your first example work as is. Say you ask for POSIX path of file "Users:mkelly". If you refer to a disk that doesn't exist, i.e. "Users", it will just convert all the colons to slashes and slap a slash on the front, so you get "/Users/mkelly", which happens to be the correct answer. The original HFS path is still technically wrong, though: if you ask for POSIX file "/Users/mkelly", you'll see the real one, which includes the disk name.
_______________________________________________
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.
  • Follow-Ups:
    • Re: More newbie queries: paths
      • From: Michael Kelly <email@hidden>
References: 
 >More newbie queries: paths (From: Michael Kelly <email@hidden>)

  • Prev by Date: question: <<event coregetd>> & print multiple copies
  • Next by Date: AppleScript Studio: how to run a script on launch?
  • Previous by thread: Re: More newbie queries: paths
  • Next by thread: Re: More newbie queries: paths
  • Index(es):
    • Date
    • Thread