Three 'Panel Ended' Questions

Hi everyone, I have three questions,

  1. If I have multiple panels, an ‘Open Panel’ and one created in IB, how am I going to filter them in my handler? I know how to do it like "if name of theObject = “whatever” then but how am about doing that with panels ? (and especially Open Panels?) do I need to filter it like : “on panel ended theObject with result withResult” but then with a different variable as result ?

  2. If I have an Open Panel, can I force the user to select a file before he/she can click the button that performs the action ? (the not Cancel one)

  3. If one selects a file/folder, my application processes a code, while processing, the open panel keeps open… Can I somehow close the panel and then perform the actions?

Thanks for any help :slight_smile:

Hi,
here’s some direction, not necessarily the complete answer.
1- open / save panels are different from user-created panels. you don’t have to worry about open/save panels. just use it. Look in the example files for Save Panel project and Display Panel project. These will show you how to have a separate panel nib, and attach that to the script.

2- I don’t think you can press OK/Open if there is no file selection. ? You can restrict an open dialog to only folders or only files, or hide invisible files, etc.

3- I am not sure what you mean with this question. If you make a panel, you must specify in the code to not do anything until the panel closes. I believe you are right in point 1 with “on panel ended” not just “display panel”. Using one method will continue your script, and the other will stop until the panel is closed by the user pressing a button. If you are making a panel yourself to use as an open panel, you’re doing something wrong.

This was just from the top of my head I haven’t rechecked any code.

  1. I’ll take a look later on
  2. Fixed it, when the selected file is not a “good” file, the code in my script displays a message, if it is such a “good” file it processes code.
  3. No, I haven’t made my own open panel, my code creates an open panel with AppleScript like in the “Open Panel” example. The panel is attached so it uses the on panel ended handler, in that on panel ended handler, the files are processed one by one which sometimes can take some time… So what I mean is, the user selects a file/folder, clicks “OK” (or whatever), the panel closes and my code processes the files/folder. But what I have now is that the code processes and then closes the panel.

Thanks for your help :slight_smile:

If you don’t explicitly close the panel yourself then the panel won’t actually close until the end of the “panel ended” handler. As such you just close the panel yourself before you execute any code. Here’s an example of how to do this for both an open panel and one you’ve created yourself.

on panel ended theObject with result withResult
		if (theObject is open panel) and (withResult is 1) then
			close panel open panel
			-- do your stuff here
		else if name of theObject is "whatever" then
			close panel theObject
			-- do your stuff here
		end if
end panel ended

Thanks a lot, now everything works like I wanted it :slight_smile: I really appreciate it.