Re: Best practices
Re: Best practices
- Subject: Re: Best practices
- From: Emmanuel LEVY <email@hidden>
- Date: Fri, 18 Feb 2011 01:42:35 +0100
For those interested, absoluteURL makes what it says, that is making a
relative URL or path + a base path or alias into an absolute path, but
it also "resolves" things which are not explicit paths. Like "./"
which stands for "up one level" or "~" which stands for "/Users/
<current user>".
For those interested, most of Satimage stuff understands the "~"
shortcut.
You're absolutely right.
Most of our programs do simple stuff such as concatenation etc. but
we do use one command to take care of the posix path tricks,
mainly ../ and ~
That's Satimage osax' absoluteurl command's mission.
absoluteURL v : resolve a relative URL using a base URL or coerce an
absolute URL.
absoluteURL string or alias : a (possibly) relative URL. (Or a list
of such.)
[from string or alias] : the base URL
[as type] : Unicode text, alias, unix path, path...
→ string : an absolute URL
On Feb 17, 2011, at 2:02 PM, Mark J. Reed wrote:
POSIX paths are nice in some ways, but tricky as well. They're not
really *just* strings, because they have non-stringlike semantics.
If your app treats them as black boxes, fine, but if it cares e.g.
whether two paths refer to the same file, then you can't just do a
string comparison. Forget symbolic links or pathological things like
"../././/..//./.."; even just recognizing that "foo" and "./foo" are
the same file (or that "the directory part of 'foo'" is somehow ".")
takes an amount of care and code. Are doubled slashes OK? Do
directory paths end in "/"? That matters when you have directory path
d and file name f and want to put them together - is it just d&f or
is it d&"/"&f? What if d is just "/"?
It's nice to have an abstraction layer that takes care of those
details for you. AS doesn't really have one of those, so you wind up
using external apps that do.
On Thursday, February 17, 2011, Emmanuel LEVY <email@hidden>
wrote:
Sorry, I'm not sure at all that all apps like "posix file f".
We don't use any app actually - none is fast and reliable enough
for us, including System Events [1] - only StandardAdditions. "info
for" and the like work well with "posix file f".
posix paths are lovely, because, well, you just manipulate strings,
specifying a file's container folder is a mere regular expression,
etc.
Emmanuel
[1] I posted here our instead-of-System-Events osax, Files.osax.
On Feb 16, 2011, at 11:03 PM, Shane Stanley wrote:
On 17/2/11 1:56 AM, "Emmanuel LEVY" <email@hidden> wrote:
I've got one, if you like.
Never use anything else than posix paths. Whenever some command
doesn't like posix paths, just insert "posix file" before the posix
path.
Being consistent has merit. Are you sure all apps that require
aliases will
accept furls instead?
--
Shane Stanley <email@hidden>
'AppleScriptObjC Explored' <www.macosxautomation.com/applescript/apps/
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden
)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden
)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden
--
Mark J. Reed <email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden