Formatting Dialogs... is it possible?

Is there a way to format strings that are pushed to dialogs? I do realize that “display alert” carries with it bolded text… but what about “display dialog”? :confused:

I was hoping to be able to italicize or even bold certain strings or words of the dialogs… unfortunately not even Pashua from Bluem: https://www.bluem.net/en/projects/pashua/ could get me there, so I thought I would ask you all if such secretive miracles exist.

I’d like to tell you there is a reward for such information, but… unfortunately, all I have to offer is my thanks in advance for the effort. :cool:

OK, I’ll buy you a beer, mead, wine - whatever your poison is… but that is, of course, predicated on the strong hunch it’s just not possible to format text in dialogs. :frowning:

That there is no markup (rich text) in dialogs is quite simple to explain. The limitation is what kind of tekst object is shown in the window. The dialog makes use from system provided UI objects. The UI objects used in dialogs are all labels. Labels are in fact NSTextField objects who are not editable, have no bezel and no background. Standard system provided NSTextField doesn’t have rich text but only plain text however you can change the style of an entire field so therefore an display alert has an bold label and an normal label which can be set by the direct parameter and message parameter respectively.

So how can you make a dialog with rich text would be the question. And the answer is quite simple: AppleScriptObjC. However when you’re not familiar with AppleScriptObjC the following can be quite hard to understand. With AppleScriptObjC you can send and receive Objective-C messages and therefore you can make use of NSTextView class which contains an NSText class for showing rich text on you screen. When you set an NSAttributedString to an NSText you can create rich text on the fly. An attributed string is pretty much like how rich text works in TextEdit.app and AppleScript. You have plain text and an attributed run over it. An attributed run is like an list with consecutive ranges who contains the markup of the range.

Another way, which I would prefer, is showing an subclassed NSTextView with markdown support for example. There are many subclasses of the NSTextView available on github for example so you only need to provide the dialog markdown text. You wrap it in your own framework and use it in AppleScriptObjC.

Good luck finding someone who wants to do this for you.

You can also set a text field to an attributed string directly, using the attributedStringValue property it inherits as a subclass of NSControl. The actual drawing of text fields is done by the window’s field editor anyway, which is a shared text view.

You could actually modify my Dialog Toolkit library to handle it fairly easily – as long as you were willing to pass it an NSAttributedString. I suspect that building the attributed string would be the biggest challenge, as DJ alludes, unless you could use something like Markdown mark-up and some conversion code.

I have to say, though, that the whole idea sounds like a recipe for dialogs that would soon start looking like bad ransom notes. When a facility like this is missing, there’s generally a sound reason.

Thank you both for the interesting and invaluable insights. :cool:

Bad ransom notes are what I am aiming to avoid… and it is only minimal formatting beyond bold I seek, as well… and I understand the mechanics at play to get it done thanks to these insights…