Excecute function after "panel ended" is done?

Hi, This is my first port in this exelent forum. Seems to land here everytime I try to google my way to a scriptsolution :smiley:

Anyway, I’m currently doing a script which executes long line of events when I open a file using a open panel (as a sheet).

I trigger the events in the “panel ended with result…” function. But since my script takes quite som time to run the open-sheet stayes open until all the code has executed. This is really annoying for the look and feel of my application.
The only thing i really need from the “panel ended” call is the filepath, but I want to run the rest of the script without user interaction once I got the path.

Is there a way to execute a function directly after “panel ended” has “ended” since that’s when the sheet closes…

Cheers!
Kalle

Model: Screenspanned iBook G4
AppleScript: latest
Browser: Firefox 1.5.0.1
Operating System: Mac OS X (10.4)

I’m looking to do the same thing. Why does the “on panel ended” code get executed before the panel is actually closed? Doesn’t make any sense…

Because of the way that the applescript ‘panel ended’ handler is linked to the underlying cocoa method it calls, this is actually the way it should behave. If you return control to the interface before you’ve handled the open panel action, you might end up getting conflicts or undesirable behavior. The open panel not only gives you a chance to choose items… but also to then DO something with the items. If you’ve got a bunch of code to execute after selecting some files, it’s a GOOD idea to do that before the panel closes so the user isn’t off clicking buttons and making changes in your interface before you’re actually ready. If you’re against this approach, you can certainly force the open panel to close, and then execute your code… a common practice in working with the open, save, and custom panels. If you’re going to override the “natural flow” of how code is executed by the handler, though, make sure to account for this in your interface and your code. You may need to disable certain controls and otherwise make sure the user can’t fudge with things before the code is all executed. If you are executing lots of code when the panel ends, it’s usually more intuitive for the user to have to wait for the panel to close until after the task is complete. If you close the panel before the task is complete, you might potentially lead them to believe that it’s already done and they’re free to move on. Given the right circumstances it may be appropriate to close the open panel first, but you should probably then display some other window, view, or message that tells them that something is still happening.

By simply telling the panel to close after you’ve got your info from it, you can execute your code after the panel “ends”, or closes…


on panel ended theObject with result theResult
	if theResult is 1 then
		set theItems to (path names of open panel as list) --> Get the item(s) selected in the open panel
		close panel theObject --> Close the panel immediately
		log (theItems as string) --> Do something with the items
	end if
end panel ended

j

Thanks, Jobu!

Yes, that’s exactly what I wanted. My panel is just collecting some optional text input, and the main window was displaying results that were being obscured by the panel as it executed the code. I actually had tried to close the panel explicitly in the ‘on panel ended’ handler, but my syntax must have been wrong. I tried closing the panel by name, which did nothing, but using theObject works and makes much more sense. Thanks again!