Dialog Toolkit Plus isMainThread Error

dean. I did delete Shane’s version of Dialog Toolkit Plus and renamed your version to Dialog Toolkit Plus.

Just to check this, I copied your version to another folder, deleted it from the Script Libraries folder, rebooted the computer, and then ran my script, which returned:

Error Number: -1728
Can’t get script “Dialog Toolkit Plus”.

I copied your version of Dialog Toolkit Plus back to the Script Libraries folder. I then ran my script which worked fine. So my search-and-replace script is now using your version of Dialog Toolkit Plus–at least as far as I can tell.

1 Like

Sorry, I’m just not in a position to do that sort of testing at the moment. I’m getting reports of intermittent errors, but no other reports of what you are suggesting, and the time I can devote to freeware is limited.

I understand…so let me ask you what sounds like a riddle but is a real question… If a script is calling a script (menubar triggered run script) or Fast Scripts calls a script…that uses your dialog toolkit plus. The dialog is looking for main thread, is it potentially just unpredictable because all 3 use a reference to current application’s NSThread? Maybe the WindowState or other items in the plist are resolving it?

The error is that AppleScript is not loading AppleScriptObjC. If I knew why, we wouldn’t be having this thread. The intermittent nature of the problem makes it difficult to solve – it has been happening for years, and no-one has come up with an explanation.

That said, there’s no reason for AppleScript to even read the Info.plist file, unless there’s been a regression with OSAAppleScriptObjCEnabled. And if that were the case, I’d expect it to be 100% reproducible. WindowState is a red herring (it’s the settings for Script Editor’s window when the script was last saved).

1 Like

I’ve been using dean’s revision of Shane’s script for two days and haven’t received the isMainThread error message even once. So, this issue appears resolved for me (hopefully). Many thanks!

1 Like

I’m glad it’s resolved. Same for me. I modified Myriad Tables Lib plist file to add the same

OSAAppleScriptObjCEnabled boolean yes

And it stopped causing the same problem. @ShaneStanley do you think this change is necessary in SMSTableDialogBuilder plist?

Try adding it and tell me. I can’t generate the problem with any regularity here.

It wasn’t necessary that I can see. Going to test for bit.

I’m not surprised. That value was introduced in 10.9 when ASObjC was first made available outside Xcode, and was dropped in 10.10 – that’s nine versions of the OS ago. It’s a long time for a regression to hang around (but then, this is AppleScript).

Im referring to it wasn’t necessary to add OSAAppleScriptObjCEnabled boolean yes to the SMSTableDialogBuilder plist file. Adding it to the Myriad tables 1.0.13 plist file has stopped it from causing the App to quit unexpectedly when triggering display table. FYI it happened more on M1 Mac Ventura then Intel Mac Ventura but still occurred and was resolved by adding that line to the plist.

Was that the only difference?

Yes. It was easier to test on Myriad Tables because the last 2 versions didn’t have that line in the plist file and they both quit until added.

I can strip down my code to send u for reference to test it but essentially I’m calling runscript from script A that runs code in script B and uses Dialog Toolkit Plus and Myriad Tables all running in Ventura on Intel and it happened 90% of time when not being run from script debugger. When I tested on M1 with a newer version of Ventura it did it 100% of time.

@ShaneStanley sent you a loom video of the error occurring and being fixed and no longer occurring.

I’ve not been able to understand all the posts on this thread but, in case it’s relevant, I found last year that editing DTP 1.1.3 in Script Editor works but editing in Script Debugger results in the “NSThread doesn’t understand the “isMainThread” message” error. I could not find out why. But, I’ve not had the error since.

@dean one other thing you could test: change the OSAAppleScriptObjCEnabled entry to NO. If the value is being read, that should guarantee 100% failure rate. If it works at all, it would suggest something more complicated is going on.

Votes are in it absolutely resolved the issue. See the other post too.

I can confirm that, since a couple of month now, all my librairies has the OSAAppleScriptObjCEnabled set to yes and I never encounter this issue again.

So, for those of us who are having this same issue with running scripts in FastScripts and other menus, the solution seems to be to locate the plist file for the libraries and set OSAAppleScriptObjCEnabled to yes.

Is that correct?

Yes. Thanks to @dean.

EDIT: Found my error in previous script. This version works.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use script "filemanagerlib"
property ASOBJCEnabledPrefKey : "<key>OSAAppleScriptObjCEnabled</key>"
property ASOBJCEnabledPrefValue : "<true/>"

on open fileList
   repeat with thisFile in fileList
      set nameExtension to name_extension of (parse object thisFile with HFS results)
      if nameExtension is "scptd" then
         set scriptLibrariesFolder to (thisFile as text) & "Contents:"
         
         set libFileList to objects of scriptLibrariesFolder ¬
            searching subfolders false ¬
            include folders false ¬
            include files true ¬
            result type files list
         repeat with aLibFile in libFileList
            set nameExtension to name_extension of (parse object aLibFile)
            
            if nameExtension is "pList" then
               my UpdatePListFile(aLibFile as alias)
            end if
         end repeat
      else if nameExtension is "app" then
         set scriptLibrariesFolder to (thisFile as text) & "Contents:Library:Script Libraries:"
         set libFileList to objects of scriptLibrariesFolder ¬
            searching subfolders false ¬
            include folders false ¬
            include files true ¬
            result type files list
         open libFileList
      end if
   end repeat
end open

on UpdatePListFile(pListfile)
   local pListfile
   set pListInfo to read (pListfile)
   if ASOBJCEnabledPrefKey is not in pListInfo then
      set AppleScript's text item delimiters to {"<dict>"}
      
      set pListInfo to text items of pListInfo
      set ASOBJCEnabledPref to return & tab & ASOBJCEnabledPrefKey & return & tab & ASOBJCEnabledPrefValue & return
      set item 2 of pListInfo to ASOBJCEnabledPref & item 2 of pListInfo
      set pListInfo to pListInfo as text
      try
         set openFile to open for access file pListfile with write permission
      on error errMsg number errNum
         close access file pListfile
         set openFile to open for access file pListfile with write permission
      end try
      set eof of openFile to 1
      write pListInfo to openFile
      close access openFile
      set pListInfo to read pListfile
   end if
   
end UpdatePListFile


1 Like