Button Question

button returned of (display dialog “Action” buttons {“Good”, “Bad”, “Cancel”} thats if i wanted to get the return of a button from a dialog box is there anyway i can get a return of a button on a window?

If you are using AppleScript Studio (and that’s this forum, so I’m assuming you are) then you will create the button in Interface Builder (probably in a window you created also, but could be the default window that IB creates for you when you create an AppleScript app).

You then need to open the inspector (“Show Info” in the Tools menu or command-shift-I). In the Inspector window, you will want to click the pop-up menu and go down to “AppleScript”. The Inspector will change to show a “name” text box where you enter the name of the button (make it up!) and below that you will see a set of actions that the button can report/respond to. You want to click the “Clicked” checkbox, then at the bottom of the Inspector there should be an empty checkbox with the name of the default AppleScript for your application. You need to click that checkbox also.

After you do all this, save the nib file (that is an Interface Builder file, usually called “Main Menu.nib”) and then go back to your script file in Xcode (or Project Builder in the older version of the dev tools). You should have a handler that looks like this:

on clicked theObject
(* your code goes here*)
end clicked

Try that and post back if you need help.

Hi,

As far as I can tell, you can get a reference to the title of the button in the window or the name of the button (as you had specified linking your button object to your script in the IB) but you can’t get “button returned of the result” as you can do in the dialog box created with AppleScript.

I tried to check in the AppleScript Studio Terminology Reference the properties of the buttons and the commands that buttons recognize but I can’t find anything there that is remotely similar to what you want.

Hope this clears things up for you. If it turns out that I am wrong, I would gladly stand to be corrected.

archseed :slight_smile:

Archseed, you’re correct. The idea behind AS Studio is not quite that of a regular AppleScript. The code doesn’t “flow” but is instead event driven with handlers called when events happen (much like the old Hypercard program).

So when a button is clicked (or moused on, in, or dragged) a handler is called. But since buttons can all call the same handler, the way I determine which one is being used is by doing something like:


on clicked theObject
if the name of theObject is "myButton" then
(*your code for the button here*)
end if
end clicked

Effectively giving you the same information you would get from “button returned from the result”