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 19:54:36 +0100
Shane Stanley wrote:
>But you've left out the choice of Unicode HFS paths.
Not as bad as string HFS paths, not as good as Unicode text POSIX paths. Did you read the BBS thread I posted?
> > The only app I know of that has issues with HFS vs POSIX paths is Finder
>
>You need to get out and mix more.
Feel free to provide a full list of apps that require HFS paths; it might be a useful thing to have around.
> > Pretty much every other scriptable application and osax should not, and do
> > not, use path strings at all.
>
>That's great, but let's get back to the real world. Script Editor returns
>what for the path of a document?
POSIX path. (Yes, I forgot about this particular case; it's a long time since I stopped bothering to keep track of all the bugs and flaws in Cocoa Scripting and Apple apps. Sue me.) BTW, this is Cocoa Scripting's fault, not SE's; you'll find the same in other Cocoa apps. But at least it's a POSIX path, not an HFS one, so while it may be inconvenient it's not an "issue", i.e. it doesn't introduce any additional problems.
>What do apps like Word and Excel require to open a file?
Been a while since I've been near those (I still miss Word 5); these days they've got the pig-ugliest "AppleScript" interfaces I've ever seen. Yep, newer versions have Open commands with an undocumented need for HFS paths (if MS _had_ to use paths in their OS X apps, they should've at least used POSIX paths). Fortunately, Word and Excel are in the 'not pretty much every other application' category.
Incidentally, they do actually accept file objects in their standard 'open' commands. It's just that the custom 'Open' keyword normally masks that command when you compile an AppleScript, though you can force it to use 'open' if you need to:
tell application "Microsoft Excel" to «event aevtodoc» (alias "MacHD2:Users:has:Workbook1.xls")
But anyway, what's your point? I never said _never_ use HFS paths, just not to use them when you can use POSIX paths instead. Which is the vast majority of the time.
>There's little consistency.
The level of consistency (at least on the basic stuff) is actually pretty good between applications. Even down to Cocoa apps sharing the same design flaws.
> > Look, I'm against ASers directly mucking about with file paths as a matter of
> > course, period.
>
>Meanwhile back here on planet Earth we have to do these things regularly,
I've already acknowledged that AppleScript's standard library is utter cack, which _forces_ users to use whatever ersatz alternatives they can mash together for themselves. On a non-sucky language like Python, for example, I just do 'from os.path import *' and instantly I've several dozen commands to do all this path-munging crap for me. You're the one living out in the boonies, not me.
>and in many cases they strike me as easier to do with HFS paths.
property _SomeLib : load script alias ((path to scripts folder from local domain) as Unicode text & "ASLibraries:SomeLib.scpt")
property _SomeLib : load script POSIX file (POSIX path of (path to scripts folder from local domain) & "ASLibraries/SomeLib.scpt")
Yeah, really onerous.
> > 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 if that point is moot, then the point of choosing HFS paths over POSIX
>paths for, among other things, ease of manipulation, is valid.
[Uh, non sequitur much? Different point.] Ease of manipulation is no harder with POSIX paths; AppleScript makes it laborious either way.
Anyway, if all you care about is 'easy to do', just write all your scripts as:
on run
end run
May not do exactly what you wanted but damn is it easy, and as a bonus it'll run super-fast too.
> > 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.
>
>Who said "strings"? I'm talking HFS paths in Unicode. And you just said that
>POSIX paths don't always work properly,
No, POSIX paths themselves are just peachy; it's an industrial-strength system. I said certain bits of AppleScript's POSIX path support don't work properly, but not enough to prevent you using them. AppleScript's HFS path support may work, but HFS paths themselves are fundamentally flawed. Is it a flaw that will bite everyone all the time? No. But unless you're a total hack why would you want to invite trouble?
>so what is your definition of "safely as possible"?
Dump AppleScript and go use Perl/Python/Ruby/Tcl/whatever. Where that's not an option, spend a significant amount of time learning where all AppleScript's bugs, flaws and limitations lie, and how to work around them.
>On a practical note, if I have the choice of a system
>that will fail if two disks are the same name, or a system that might fail
>with non-English characters, I know which is easiest to deal with.
You don't bother to actually read what I write, do you? I said 'posixPath as POSIX file' appeared broken, but I've had no problems using 'POSIX file posixPath'. BTW, you are aware AppleScript's Unicode support is flaky all over? If you're really that concerned about robust Unicode support you shouldn't be using it at all.
> > 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.
>
>OK, so I 'tell app "Whatever" to smack head'. Now I have to do some work
>with it. Sadly, I don't feel much better.
Again, where did I say one must _never_ use HFS paths? I feel like I'm kicking a strawman here.
> > 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.
>
>But surely the decision should be based on practicalities
Gee. What have I been saying all along?
>rather than vague references to things being "kinda legacy".
Mac OS X, as you might have noticed, uses POSIX paths. HFS paths are a Mac OS 9 feature. Their presence in OS X is due to the need to maintain backwards support with older pre-OS X software (such as AppleScript). It's a pity that AppleScript isn't trying harder to leave behind its Mac II/System 7 roots and become a completely naturalised OS X citizen as there's a lot of old guff in it that its users could do without. But like I say I can't see this happening before AS 2.0, so nobody should hold their breath.
You know, I find it severely ironic that in AppleScript, an ostensibly end-user oriented language, users are forced to deal with two different path schemes, three different file objects, virtually no built-in tools for working with them and a swathe of bugs and limitations affecting them all. (I do feel for poor Matt, having to try steering his readers through all this crap without his or their heads exploding.) Meanwhile in [e.g.] the dreaded Python, the _only_ thing you need to deal with is POSIX path strings, plus you get a nice set of functions for manipulating them thrown in for free and Everything Just Works. Hey, can you guess which one is easier to use? Maybe I'm not the only one who needs to get out more, huh?
Anyway, you can have the rest of this thread 'cos I've had enough of it.
has
--
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