RE: Capturing current handler name in a string variable
RE: Capturing current handler name in a string variable
- Subject: RE: Capturing current handler name in a string variable
- From: Joe Kelly <email@hidden>
- Date: Thu, 27 Dec 2001 11:39:38 -0800
I've always thought about writing an AppleScript pre-processor. I've mainly
thought of all the cool uses for macros and includes, but for debugging
purposes it would be awesome to catch an error that said "'Script doesn't
understand GoLive() message', -3208, File: 'automakelite.scpt' Line: 214,
see log for call stack."
I've never used anything except Script Editor. Do any of the more feature
laden scripting application have such a thing? Smile, ASS, Script Debugger,
FaceSpan, etc? If not, I might just play around with the idea a bit.
joe
>
-----Original Message-----
>
From: billp [mailto:email@hidden]
>
Sent: Tuesday, December 25, 2001 7:19 PM
>
To: Sander Tekelenburg; AppleScript Users list
>
Subject: Re: Capturing current handler name in a string variable
>
>
>
Sander,
>
>
I was rather hoping applescript would have a command to capture the
>
current
>
handler name that would be more portable. For example, the
>
command below:
>
>
>(* your handler: *)
>
>on BeepBeep(myString, theButton, icon_number, n)
>
> -- set this handler's name to a variable
>
> set myName to "BeepBeep"
>
>
which requires me to type the name of the handler myself as a string,
>
cannot ITSELF become a handler - it needs to be embedded into every
>
single
>
handler that I want to give its capabilities to...
>
>
...it would be cool if the last line COULD be expressed
>
something like:
>
>
> set myName to name of me as string
>
>
... which does compile, by the way, but produces the following error:
>
>
"can't make name of <<script>> into a string."
>
>
...which I guess means that given there may be a number of
>
handlers in
>
the file
>
at the same time, it wouldn't know which "Me" it was referring to...
>
>
Oh well, thanks for trying!
>
>
Bill
>
>
>-----BEGIN PGP SIGNED MESSAGE-----
>
>Hash: SHA1
>
>
>
>At 19:02 -0600 UTC, on 24-12-2001, billp wrote:
>
>
>
>> [...] is it
>
>> possible in AppleScript to capture the name of a
>
particular handler or
>
>> object being referenced at a given time and set it as a string to a
>
>> variable?
>
>
>
>Might something along these lines be useful?
>
>
>
>(* beware of line breaks! *)
>
>
>
>(* set your variables as before *)
>
>set {theString, theResponse, theIcon, theCount} to {"Let's
>
beep.", "Yeah,
>
>let's.", 1, 2}
>
>
>
>(* call your handler and catch its result *)
>
>copy my BeepBeep(theString, theResponse, theIcon, theCount)
>
to {HandlerName,
>
>itsArguments}
>
>
>
>(* log your handler's name, and the parameters it received *)
>
>my logHandler(HandlerName, itsArguments)
>
>
>
>(* your handler: *)
>
>on BeepBeep(myString, theButton, icon_number, n)
>
> -- set this handler's name to a variable
>
> set myName to "BeepBeep"
>
>
>
> --handler does its stuff
>
> display dialog myString buttons {"Cancel", theButton}
>
default button 2 with
>
>icon icon_number
>
> beep n
>
>
>
> -- return this handler's name and the arguments it received
>
> return {myName, {myString, theButton, icon_number, n}}
>
>end BeepBeep
>
>
>
>
>
>on logHandler(HandlerName, itsArguments)
>
> -- do stuff. Like write to file, or display a dialog:
>
>
>
> -- coerce arguments to nicer format
>
> set niceArguments to ""
>
> repeat with i in itsArguments
>
> if (class of i = string) or (class of i = text) then
>
> set i to "\"" & i & "\""
>
> end if
>
> set theItem to i & ", "
>
> set niceArguments to niceArguments & theItem
>
> end repeat
>
> set niceArguments to characters 1 thru -3 of niceArguments
>
>
>
> display dialog "Handler \"" & HandlerName & "\" was
>
called with these
>
>parameters: " & (niceArguments as string)
>
>end logHandler
>
>
>
>
>
>-----BEGIN PGP SIGNATURE-----
>
>Version: PGPfreeware 7.0.3 for non-commercial use
<
http://www.pgp.com>
>
>
iQA/AwUBPCivkusywKfXgqKdEQKslACgh5ct2w19rwsvkEHWuKVsUAKfg8wAoLpe
>
LSSU3vTA9wgIrqmtuJVBhYnW
>
=JAPu
>
-----END PGP SIGNATURE-----
>
--
>
Sander Tekelenburg
>
_______________________________________________
>
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.
_______________________________________________
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.