[comp.sys.mac.hypercard] Intercepting Command-Dot

willcox@urbana.mcd.mot.com (David A Willcox) (10/02/89)

I've stumbled across what seems to be an undocumented feature of
HyperCard: If you type command-period while a HyperTalk script is
running, the script stops. 

That's real handy for stopping an errant script, and I suspect that a
lot of you out there already know about it.  (Sure wish I had know
about this a month ago when the only way I could think of to get out
of an runaway script was hit the old programmer's button.)

My question:  Is it possible to catch the command-dot as an event to
allow the script to do some cleaning up if it gets cancelled?  At the
very least, I'd like to get back to the starting card.  I'd also like to
let an XCMD clean up its memory.  For example, I'd like to be able to do
something like:

	on commandDot
	    if inScript then
		pop card
		myXcmd "cancelled"
	    endif
	    pass commandDot
	end commandDot

	on myFunction
	    push card
	    put true into inScript
	    myXcmd "start"
	    repeat forever
		go next card
		myXcmd "continue"
		<stuff>
	    end repeat
	    myXcmd "done"
	    put false into inScript
	    pop card
	end myFunction

Any suggestions on how to do this?
--
David A. Willcox
Motorola Urbana Design Center	UUCP: ...!uiucuxc!udc!willcox
1101 E. University Ave.		INET: willcox@urbana.mcd.mot.com
Urbana, IL 61801		FONE: 217-384-8534

bskendig@phoenix.Princeton.EDU (Brian Kendig) (10/04/89)

In article <1071@urbana.mcd.mot.com> willcox@urbana.mcd.mot.com (David A Willcox) writes:
>I've stumbled across what seems to be an undocumented feature of
>HyperCard: If you type command-period while a HyperTalk script is
>running, the script stops. 

Actually, this is one of those little things that works universally in
any Mac program that's worth its snuff.  If your Mac is doing something
strange or being very slow, hit Command-period.

>That's real handy for stopping an errant script, and I suspect that a
>lot of you out there already know about it.  (Sure wish I had know
>about this a month ago when the only way I could think of to get out
>of an runaway script was hit the old programmer's button.)

The power switch works nicely, too, as does a firm tug on the power cord...

>My question:  Is it possible to catch the command-dot as an event to
>allow the script to do some cleaning up if it gets cancelled?  At the
>very least, I'd like to get back to the starting card.  I'd also like to
>let an XCMD clean up its memory.  For example, I'd like to be able to do
>something like:
  +++ example nuked +++
>Any suggestions on how to do this?

Well, you can't trap the Command-period - it breaks out of any script that
is running, so therefore by definition it would automatically break out of
any script designed to trap it!

Instead, you might do this:

  on <whatever>
    global working
    put true into working
    ...
    put empty into working
  end <whatever>

This makes a global variable, "working", be true if your script is doing its
stuff, and empty otherwise.  If your script exits properly, working will be
reset to empty.

However, when no other script is executing, the system repeatedly sends out
'idle' messages.  Idle will be called until you enter <whatever>, and will
be called again immediately upon exiting <whatever>.  Idle will never realize
that 'working' had been set to true...

... unless you hit Command-Period before <whatever> returns 'working' to
empty.  If you hit Command-period in the middle of <whatever>, <whatever> will
abort, and any handler beginning with 'on idle' will be called.  Naturally,
the 'idle' handler will realize that 'working' is still true.

  on idle
    if (working is true) then cleanUpStuff
  end idle

  on cleanUpStuff
    ...
    global working
    put empty into working
  end cleanUpStuff

I hope this points you in the right hyperdirection!

     << Brian >>
-- 
| Brian S. Kendig       |  I feel more like I   | bskendig                   |
| Computer Engineering  |  did when I got here  | @phoenix.Princeton.EDU     |
| Princeton University  |       than I do now.  | @PUCC.BITNET               |
| Systems Engineering, NASA Space Station Freedom / General Electric WP3     |

blob@apple.com (Brian Bechtel) (10/09/89)

In article <1071@urbana.mcd.mot.com> willcox@urbana.mcd.mot.com (David A 
Willcox) writes:
> I've stumbled across what seems to be an undocumented feature of
> HyperCard: If you type command-period while a HyperTalk script is
> running, the script stops. 

Page 193, Miscellaneous keyboard short cuts, Hypercard(tm) User's Guide. 

--Brian Bechtel     blob@apple.com     "My opinion, not Apple's"

tecot@Apple.COM (Ed Tecot) (10/11/89)

Another gem from Dan Winkler:

There is no way to catch command period.  It is intended to be the ultimate
weapon against runaway scripts.  XCMD's are not affected by command period
since they have the processor while they are running.