Re: path to as string
Re: path to as string
- Subject: Re: path to as string
- From: has <email@hidden>
- Date: Fri, 1 Jul 2005 01:53:30 +0100
Shane Stanley wrote:
> > For example, HFS paths are kinda legacy and rarely necessary
>
>So what apps, exactly, do you script?
Understand, HFS paths have a fundamental flaw in that they cannot distinguish between different disks with the same name. So I'm not suggesting folk prefer POSIX paths simply for the fun of it. Nor am I saying folk _never_ use HFS paths when they've no other choice. What they do need to know is that Unicode POSIX paths are good and HFS strings are not good, so it's best to use the former and avoid the latter whenever there's a choice.
The only app I know of that has issues with HFS vs POSIX paths is Finder (and maybe System Events; I can't remember), and only when you're writing stuff like:
folder "MacHD:Users:has:"
which it allows as a special case, but not:
folder "/Users/has"
And this isn't really a big issue as you can also pass an 'alias' object (it may still barf on 'POSIX file' objects, I'm not sure).
Pretty much every other scriptable application and osax should not, and do not, use path strings at all. I'm sure we all remember the stushie circa OS 10.2 that certain Cocoa apps caused by requiring [POSIX] path strings. Since then, Apple have stated quite clearly that applications should use file objects (alias, POSIX file, etc.), not path strings.
>Are you suggesting we take paths returned as aliases or file references,
>convert them to POSIX paths, fiddle with them there (which means taking
>extra precautions about things like slashes in names) and then turn them
>back to aliases, file references or HFS paths
Because, obviously, the traditional hack practice of coercing aliases or file references to strings, fiddling about with them there (which means taking extra precautions about things like colons in names) and then turning them back into aliases or file references is so much better. Especially the coercing to string bit; bet that's never bitten anyone on a non-English filesystem. And too bad if you've two drives with the same name, cos that's just a crapshoot with HFS.
Look, I'm against ASers directly mucking about with file paths as a matter of course, period. It only creates extra work and more opportunity for mistakes. There should be a set of standard library commands that provides all the day-to-day functionality needed to split, join and otherwise wrangle path strings in complete safety. But AppleScript doesn't have a standard library worth a damn, and it's nigh well impossible to get ASers to accept a third-party one, so the point is somewhat moot. So as long as they're going to mangle them directly, they should at least be shown how to do it as safely as possible, which means using POSIX paths and Unicode text, not HFS paths and strings.
>because that's all most apps
>will accept (and what, last time I looked, the guidelines say they should
>all accept)?
Again, the SIG is quite clear that they should NOT be dealing in path strings, either POSIX or HFS. And any app that barfs on a 'POSIX file' object deserves a solid smack in the head because that's just sloppy implementation. [1] Still, it's not like you can't coerce from POSIX file to alias (or even <spit> 'file specification') if you have to.
> > Admittedly, AppleScript also manages to botch these in various places.
>
>What the hell -- better to have something that doesn't work than something
>that's "kinda legacy", huh?
You can deal with its botched 'string' implementation, or its botched 'Unicode text' implementation. You can deal with its botched HFS path support, or you can deal with its botched POSIX path support. In case you haven't noticed, the AppleScript language is buggier than an anthill - so you're going to be dealing with bugs either way. But at least with Unicode text and POSIX path you aren't having to deal with System 7-era limitations, duplicate drive names and internationalization issues as well.
has
[1] If a command needs a parameter as an AEDesc of typeAlias, it should ask the AEM to supply that parameter as typeAlias; the AEM will do any necessary coercing automatically.
--
http://freespace.virgin.net/hamish.sanderson/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden