Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What's going on here?



Title: Re: What's going on here?
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.)

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:
http://lists.apple.com/mailman/options/applescript-users/email@hidden

This email sent to email@hidden

References: 
 >What's going on here? (From: Adam Bell <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.