Re: What's going on here?
Re: What's going on here?
- Subject: Re: What's going on here?
- From: Adam Bell <email@hidden>
- Date: Thu, 29 Jun 2006 15:09:49 -0300
- Comment:
Title: Re: What's going on here?
At 10:40 AM -0700 6/29/06, Paul Berkowitz wrote:
On 6/29/06 9:28 AM,
"Adam Bell" <email@hidden> wrote:
At the heart of a more complex script
failure, I discovered
this:
{count 1234,
count "1234"} --> {0,
4} in an editor, but
fails with "1234 doesn't understand the count message" if
compiled.
Why does this work from the editors, but not when compiled?
It works fine here:
set
x to {count 1234, count "1234"}
set AppleScript's text item delimiters to {";
"}
set
x to
x as string
set AppleScript's text item
delimiters to {""}
display dialog
x
--> "0; 4"
displays from this script saved as a compiled .scpt and run from the
system's Script menu.
However when saved as an application, I get the error you see
when the app is double-clicked.
So it's nothing to do with the compiling as such. When run in a
scriptable script editor, 'count' is implemented by the application
(the script editor). When run from the script menu, 'count' is
implemented by System Events, which runs the script menu. When saved
as an application, AppleScript itself handles 'count'. It works OK if
you ask it to just count "1234" - the string. It's only when
you ask it to count an integer (1234) that it has a problem and
errors. So it must be that "counting" an integer is not a
valid operation as such, and that applications that implement 'count'
in the Standard Suite implement some sort of coercion such that
"counting" an integer results in 0 rather than erroring. (If
anything, you might wish the coercion to count the number of bytes in
the integer, but it doesn't. It comes up with 0 - which is not
accurate or meaningful. Frankly, I'd prefer the error to
0.)
So would I. Your theory about the editor interpreting is borne
out by this script which works very nicely when compiled:
tell application "Script Debugger
4"
to display
dialog (count 1234) --> 0
So does your script, as
expected, with this change:
tell application "Script Editor" to set x to
{count 1234, count
"1234"}
set AppleScript's text item delimiters to
{"; "}
set x to
x as string
set AppleScript's text item delimiters to
{""}
display
dialog x
It's evidently some sort of coercion that 'count' as part of the
Standard Suite does when applications implement it, but AppleScript
itself does not. I wouldn't trust that 0 if I were you - the error is
better. Trap for the error in a try/error block and do something with
it.
--
Paul Berkowitz
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list
(email@hidden)
Help/Unsubscribe/Update your Subscription:
>esscable.net
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:
This email sent to email@hidden