(Sort of ) newbie question - trouble with button on panel

Hmm…

okay, appearantly it’s been a while since I logged in the last time… :slight_smile: And I’m no newbie, neither to AppleScript nor to coding in general. But I’m pretty new to AppleScript Studio apps, and have a little problem with getting a sheet/panel to work.

Here’s the situation:

I’ve got a little application that, at one point, brings up a sheet, using this code:


display window "panel" attached to window "mainWindow"

This is working alright. Now, the panel’s got an “OK” button on it, and as soon as I click that little sucker the trouble begins:

Behaves as if I forgot to specify a handler for the “on clicked” or “on panel ended” events, doesn’t it? But I did! Here’s what I’ve already checked:

  • “on clicked” and “on panel ended” handlers present in application script
  • (AppleScript-) name of “OK” button correct, button has “on clicked” handler and connection to application script checked in it’s AppleScript properties in IB
  • panel window name correct, has connection to application script
  • window “mainWindow” has “on panel ended” handler checked in IB and is connected to application script as well

Ideas, anyone?

Greetings,
danB

The first problem I see is in the syntax of your display command. I think the correct syntax for your case is to use the ‘display panel’ command rather than the ‘display’ command…

display panel (window "panel") attached to window "mainWindow"

It’s surprises me that the code you posted actually works. The display command by itself is really for plain dialogs, alerts, etc. It’s not really meant for panel windows. On this same note, make sure that you’re using an actual ‘panel’, and not a regular ‘window’ object.

The second conflict I see, is that if you’ve created a panel window in IB you can not use the ‘panel ended’ handler to capture the button pressed in the panel. The panel ended handler is for system panels like the open panel and save panel, not for user-created panels. There may be a method of using the panel ended handler in this way, but I don’t see the value in doing it. Instead, you should to connect the button as you would in any other window, and use the clicked handler to do all of the work…

on clicked theObject
	if name of theObject is "Panel_OK_Button" then
		close panel (window of theObject)
		--> Execute your 'OK' code here
	end if
end clicked

I would think that one of these should solve your problem. Let us know if not.
j

Well, I did use the display command instead of display panel since Apple itself says so (have a look at the “display panel” entry in the AppleScriptKit Dictionary :wink: )

Also, yes, I did use a panel object for my panel…

Did that, doesn’t work… :frowning:

Okay, got it working now. What I did was moving the query for the panel button to the beginning of the “on clicked” handler. I.e. my “on clicked” looked like this:


on clicked theObject
    if name of theObject = "a"
        dosomething()
    else if name of theObject = "b"
        dosomethingelse()
    else if name of theObject = "panelOkButton"
       close window...

…with “a” and “b” being objects in the main window. Now, as I said, moving the button to the top of the if-block solved the problem - tho I don’t have the slightest idea why…
:oops:

Nice to see you again, danB! :wink: