Re: Strange path
Re: Strange path
- Subject: Re: Strange path
- From: Paul Berkowitz <email@hidden>
- Date: Wed, 21 Jul 2004 13:41:21 -0700
On 7/21/04 1:05 PM, "John Stewart" <email@hidden> wrote:
>
On 07/21/04 at +0100 Nigel Garvey said this
>
>
> You probably have AppleScript's text item delimiters set to "/". As Paul
>
> says, concatenating a string to an alias produces a list. The oblique
>
> stroke would be introduced if you had the TID's set to that when you
>
> coerced the list to string. The default setting for TID's is {""}.
>
>
Nigel & Paul
>
>
A two item list (or barring that an error) is what I expected here but didn't
>
get, did you try it? It seems there is an unexpected backward coercion
>
somewhere. I'd like to know if it's just on my machine.
>
>
set x to path to preferences
>
set y to x & "foo" as text
>
>
--> G5:Users:john:Library:Preferences:foo
Leave out 'as text' and you'll see the list. The 'as text' coerces the list
to text and - as it always does - it coerces individual items to text too if
they can be so coerced (otherwise you'll get an error instead).
As Nigel astutely pointed out, the reason why Matt was getting that
extraneous "/" whereas you - and I - don't, is because Matt must have had
text item delimiters set to "/" (or {"/"}. When coercing lists to text,
AppleScript uses the current text item delimiters.
It just proves how you must always set the delimiters to what you want (here
the default of {""}) before coercing lists to text, string or Unicode text.
And why maybe it worked "sometimes" for Matt. Of course he wasn't aware he
was making a list in the first place.
It's also useful in showing that the only time you need 'as text', 'as
list', 'as Unicode text' in AppleScript is for making coercions. You do
_not_ need them as data type declarations if the thing in question already
is of that data type, since AppleScript does not require declarations. In
fact, it's probably better _not_ to do so. Here, if making the incorrect
assumption that 'path' was already text, and so is "foo", you'd find out
your mistake very quickly when concatenating them and ending up with a list.
'as text' hid that. And when correctly using 'path to preferences as Unicode
text' or ... as string' and concatenating another string "foo" to it you do
not need as text either.
--
Paul Berkowitz
_______________________________________________
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.