Dialog Toolkit: "create label" center align not working in macOS 12.4

Have just found a strange behaviour in Dialog Toolkit. I have this call:

set {intro_label2, theTop} to create label diag_intro_text_2 left inset 0 bottom 5 max width minWidth aligns center aligned control size small size

In macOS 10.14.6 and macOS 10.13.6, the resulting dialog shows diag_intro_text_2 correctly aligned to center. But, in macOS 12.4, that text is right aligned.

Is there something peculiar to macOS 12.4 that could be causing this ?

Thanks.

Yes, the underlying value of the constant used to specify alignment has changed – it’s a result of unifying divergent iOS and MacOS values.

You can work around thissue by changing the properties in the library. So this:

property NSLeftTextAlignment : a reference to 0

needs to become:

property NSLeftTextAlignment : a reference to current application's NSLeftTextAlignment

Do the same for the other alignments. They should then resolve correctly at runtime.

Shane, many thanks.

Where does Apple notify developers of such changes ? I find Apple’s documentation impenetrable.

BTW, Googling NSLeftTextAlignment results in this page: Apple Developer Documentation.

Apparently, NSLeftTextAlignment has been deprecated. How would NSTextAlignmentLeft be used ?

I’ve looked at the enumeration for NSTextAlignmentLRight and I’m totally lost. First it says:

Declaration
NSTextAlignmentRight = 2

But, then, there’s this note:

Note
In Mac apps, including apps built with Mac Catalyst, the value of this enumeration case is 1.

So, does that mean the declaration is really NSTextAlignmentRight = 1 ?

OK, I’ve updated the library to version 1.1.3 to fix this issue.

It was in release notes. It wasn’t well documented, but it didn’t affect most apps.

They’re the same thing, except they’ve changed a whole lot of names to a more consistent style, for the sake of Swift. It’s better in ASObjC to keep using the old version, unless compatibility doesn’t matter to you.

Shane, thank you for this.

I made what I thought were the required changes to the Toolkit code. It worked for a while with center alignment where I needed. But after a few days, Script Debugger started banging “Scripting Component Error” when I tried to compile my script. I was able to compile by commenting out a “display dialog” I use for testing. So, I could then run the script. I use a Try/On Error block to test the script. The TryBlock started reporting “Variable newWidth not defined” errors. I mucked around with my script some more and, then, consistently, I started getting “NSThread doesn’t understand the “isMainThread” message” errors on my script.

So, I reversed my changes to the Toolkit and all the errors ceased. Suggests I don’t know what changes to the Toolkit are need to get proper alignment in labels. These are the changes I made:

-- property NSLeftTextAlignment : a reference to 0
property NSLeftTextAlignment : a reference to current application's NSLeftTextAlignment
-- property NSCenterTextAlignment : a reference to 2
property NSCenterTextAlignment : a reference to current application's NSCenterTextAlignment
-- property NSRightTextAlignment : a reference to 1
property NSRightTextAlignment : a reference to current application's NSRightTextAlignment

Is there something else needed ?

In my script I call like this:

set {intro_label2, theTop} to create label diag_intro_text_2 left inset 0 bottom 5 max width minWidth aligns center aligned control size small size

Thanks.

It sounds like you might have multiple different versions. At any rate, the changes you made should not cause any of those errors. Restart?

Shane, many thanks for v1.1.3 of DTP. I’ve used that to make my project’s customisations and all is well.

I suspect I accidentally made a change which I didn’t notice and which caused the errors. Still got errors after quitting SD8 etc. So, I ditched my effort.

I spoke too soon. DTP v1.1.3 (with my customisations) crashes with “NSThread doesn’t understand the “isMainThread” message”. However, it only crashes if I call a DTP handler from a script running in osascript invoked by a Service. If I do the same but invoke osascript with an applet, there is no error. Also, there are no crashes in macOS 10.13.6 in both scenarios. And, no crashes if I use v1.1.2 of DTP (with same customisations).

Not sure what to do as yet. Might make using the Service to invoke osascript specific to macOS versions which work but, hide that function from macOS 12.4 and others as relevant.

That’s usually either a missing use statement, or an intermittent Apple bug where frameworks aren’t loaded.

Thanks. I suspect the latter – I can’t think of where there could be a missing use stmt. The DTP library is fine and the Service and other scripts have been working for months/years.

UPDATE: I’ve given up with v1.1.3 of DTP. I can’t find a way of stopping the NSThread error when calling from a Service. I tried the NSTextAlignmentRight/Left/Center form as in Apple’s documentation but it banged the NSThread error in every test. I tried adding use script DialogToolkitPlus in the Service but, that caused the Service to crash. I’d rather keep my function working and put up with right aligned instead of centre aligned text in the dialog. Thanks.