• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
(no subject)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

(no subject)


  • Subject: (no subject)
  • From: "Mike Miller" <email@hidden>
  • Date: Fri, 18 May 2001 15:56:19 -0500

At 12:42 PM -0400 5/18/01, Matthew Broms wrote:
>This seems like such an easy problem, but for some reason I cannot figure
>out how to quit my script. If I'm nested down several handlers and an error
>gets thrown or the user clicks on a "Cancel" dialog, I just want the script
>to stop completely, as if it finished. How can I just abort the whole
>execution?
>
>I've tried quit (tell process "myScript" to quit), exit, cancel, return,
>abort, kill, die verman! - nothing works. The best I can do is an exit
>repeat (if I'm in a loop) which just puts me back up a handler. I don't
>want to do this all the way up, but if I don't, an error gets thrown because
>the data that handler was trying to supply didn't supply it. So the user is
>presented a cryptic error dialog box.

When you get a cancel error (-128), clean up as best you can and pass it up the line:

on MidLevelRoutine(someData, someMoreData)
try
-- imagine a long script process here, that eventually sends:

error "User Canceled" errNum -128

-- if there's a problem...
on error errTxt number errNum
if errNum = -128
-- close files, do other cleanup
error errTxt number errNum
end if
end error
end MidLevelRoutine


If the script isn't a stay open applet, trap the error at the topmost level and exit your routine:

on run
try
set theFile to choose file with prompt "What file should I mess with?"
MidLevelRoutine(theFile, "foo!")
on error errTxt number errNum
end error
end run


If it's a stay open applet, you'll have to decide whether to ignore it and stay open (similar to the run handler above) or abort:

on idle theObj
try
MidLevelRoutine(storedData, "bar!")
on error errTxt number errNum
quit
end error

return 5
end idle


If you're handling Cancel already, you might want to use a different number for your abort error. Nothing forces you to use -128; it's just easy to use with the standard dialog OSAXen.

Hope this helps,

Mike Miller
ESG Labs
http://www.esglabs.com/


  • Prev by Date: Re: How do I simply quit execution?
  • Next by Date: Re: Deleting files from desktop
  • Previous by thread: (no subject)
  • Next by thread: recorder crashes system
  • Index(es):
    • Date
    • Thread