Re: Error geetting offset of char in errMsg
Re: Error geetting offset of char in errMsg
- Subject: Re: Error geetting offset of char in errMsg
- From: Nigel Garvey <email@hidden>
- Date: Wed, 13 Jun 2001 00:48:52 +0100
Paul Skinner wrote on Tue, 12 Jun 2001 03:04:43 -0400:
>
Sorry for the double post. I blew the subject on the first one.
>
>
try
>
{"a", "b", "c"} as date
>
on error message
>
message -->"Can't make {\"a\", \"b\", \"c\"} into a date."
>
set theListTextStart to the offset of "{" in message
>
-->12 when stepped. 0 when run.
>
set theListTextEnd to the offset of "}" in message
>
-->26 when stepped. 0 when run.
>
return {theListTextStart, theListTextEnd}
>
--{12, 26} when stepped. {0, 0} when run.
>
end try
>
>
Why is there a discrepancy in the results of this script when stepped in
>
Scripter and when it is run? And don't automatically point at Scripter, SE
>
returns {0,0}. Why?
The likely reason for the 0 result is that the error message is in styled
text (your AppleScript formatting), which the OSAX command 'offset' can't
handle. I don't know what version of AppleScript you're using, but
work-rounds that have worked in the past include:
on error message
set message to message as unicode text as text
set theListTextStart to the offset of "{" in message
or:
on error message
activate -- tell appropriate application
set the clipboard to the message
set message to the clipboard as text
set theListTextStart to the offset of "{" in message
or, since you know the form of the message:
on error message
set theListTextStart to 12
By the way, 'message' seems to be a reserved word on my system. It might
be better to use some variation on this instead.
NG