Friday, January 19, 2018

#1 2017-12-14 10:56:36 pm

antelop
Member
From:: New York, USA
Registered: 2017-11-28
Posts: 8

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"? hmm

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.  sad

Last edited by antelop (2017-12-15 12:22:41 am)


Best,
antelōp

Offline

 

#2 2017-12-18 07:21:21 am

DJ Bazzie Wazzie
Member
From:: the Netherlands
Registered: 2004-10-20
Posts: 2728
Website

Re: Formatting Dialogs... is it possible?

antelop wrote:

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



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.

Last edited by DJ Bazzie Wazzie (2017-12-18 08:30:55 am)

Offline

 

#3 2017-12-18 06:24:49 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5231

Re: Formatting Dialogs... is it possible?

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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#4 2018-01-11 01:51:43 pm

antelop
Member
From:: New York, USA
Registered: 2017-11-28
Posts: 8

Re: Formatting Dialogs... is it possible?

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...


Best,
antelōp

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)