1

A code like this display dialog "choose" buttons {"yes", "no"} creates a dialog with 2 buttons, in a single row, as expected.

I am trying to find out if it is possible to create more than one row of buttons.

For example, first row could have buttons {"red", "yellow", "blue"}, second row could be {"large", "small"}, and a third row could just be {"cancel"}.

Is it possible?

3
  • Regular AppleScript can't do stuff like that, but AppleScriptObjC provides access to the Cocoa frameworks, so you can make a dialog/window as ugly as you want. Commented Feb 15, 2020 at 13:42
  • @red_menace: Uglier, even... Commented Feb 15, 2020 at 14:07
  • @red_menace lolz Commented Feb 15, 2020 at 21:33

2 Answers 2

3

Because AppleScript was designed to be a automation system, as opposed to a full-fledged programming language, it has always restricted its GUI to simple 'alert'-style panels. The idea was that a script should bother the user as little as possible, showing dialogs that ask for a single piece of information and then getting out of the way so that the script could work more or less invisibly. Its native alerts have a maximum of three buttons (on the "Yes", "No", "Cancel" model). The only native way to deal with a choice of more than three items is to use the choose from list command, e.g.:

set meal to choose from list {"Hamburger", "Pizza", "Spaghetti", "Cucumber Salad", "Pork Chops", "Green Eggs and Ham"} with title "Meal Time" with prompt "What do you want to eat?"

which produces an alert like this:

enter image description here

While it's possible to create a multi-button alert with rows of buttons using AppleScriptObjC, it's a non-trivial task: a lot of effort for little reward. Basically one has to create a new alert using NSAlert, then create and attach an accessory-view in which you've added and positioned your rows of NSButtons. You'll also have to add some logic so the accessory view buttons you've created act as 'alert' buttons (meaning they dismiss the alert when clicked). Stack Overflow isn't really meant for coding services — though people do occasionally break that rule — but if you want to work through the bulk of the coding yourself, we'll happily assist you with difficulties.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks a lot for the detailed explanation. The "choose from list" may work for my needs. The multi row buttons alert seems to be quite a challenge, not worth it.
2

You may want to take a look at Dialog Toolkit. It is a scripting addition which can be used in Script Editor:

Dialog Toolkit Plus v1.0.1 and Dialog Toolkit v2.0.3

Dialog Toolkit and Dialog Toolkit Plus are ASObjC-based script libraries for showing enhanced dialogs. Add multiple text entry fields, checkboxes, popup menus, radio buttons, path controls, extra buttons and rules to dialogs. Dialog Toolkit v2.0.3 is a compatible update that fixes an issue with macOS High Sierra (10.13), while Dialog Toolkit Plus is an enhanced version that gives greater flexibility but requires macOS 10.10 or later. You can download the libraries and documentation here. (Direct Download Link)

Here are some screenshots of sample dialogs created using the Dialog Tool Kit script library, in Script Editor.app

enter image description here

enter image description here

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.