Re: Bizarre "can't get class <<bhit>>" error
Re: Bizarre "can't get class <<bhit>>" error
- Subject: Re: Bizarre "can't get class <<bhit>>" error
- From: "Nigel Garvey" <email@hidden>
- Date: Tue, 20 Nov 2007 12:57:03 +0000
Rob Lewis wrote on Mon, 19 Nov 2007 21:34:59 -0800:
>Code for a droplet:
>
>on open the_file
> display dialog "Prompt text here " & the_file default answer "" with
>icon note buttons ["Cancel", "Tag", "Tag & OCR"] default button "Tag"
> set tag_string to text returned of result
>------------------------------------------------------------------------
>-
> if button returned of result is "Cancel" then
Getting the 'text returned of result' sets the 'result' variable to a new
value, namely the text. The following line errors because text doesn't
have a 'button returned' property. The error says «class bhit» because
the droplet can't decompile the compiled token back to the keyword
'button returned'.
Your code assumes that 'the_file' is a file, but in fact the parameter
passed to an 'open' handler is always a _list_ of the dropped items. As
long as you only drag one item to the droplet, the implicit coercion in
the dialog above will produce the text you're expecting and the later
coercions to alias will work. But you'll get more errors if more than one
item's dropped at a time.
The square brackets for the dialog's button list work, but denote an
obsolete kind of AppleScript list. Curly braces are used nowadays:
{"Cancel", "Tag", "Tag & OCR"}
Brett Conlon wrote on Tue, 20 Nov 2007 17:11:41 +1100:
>This one works:
>
>on open the_file
> display dialog "Prompt text here " & the_file default answer "" with
>icon note buttons ["Cancel", "Tag", "Tag & OCR"] default button "Tag"
> copy the result as list to {tag_string, button_returned}
To complete my pedantic outing: it shouldn't be assumed that items in a
list coerced from a record are in any particular order. (They usually are
in this case, but they don't _have_ to be.) The 'tag_string' and
'button_returned' variables should be set directly to the record's properties:
display dialog "Prompt text here " & the_file default answer "" with
icon note buttons {"Cancel", "Tag", "Tag & OCR"} default button "Tag"
set {tag_string, button_returned} to {text returned, button returned}
of result
-- Or:
-- set {text returned:tag_string, button returned:button_returned} to result
NG
_______________________________________________
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