Scripting Changes (or lack thereof) in macOS Tahoe

One change I’ve noticed with Tahoe is that Script Debugger does not always work reliably. Most notably, the app will occasionally beach-ball for 10 seconds or so before completing some task.

Script Debugger was retired 11 months ago, and additional issues will almost certainly arise. So, I thought it was time to see if Script Editor could be used to write ASObjC scripts. The answer is yes but with two reservations.

When writing a new ASObjC script with Script Editor, I have to save the script almost immediately. If not, I get the following error and compiling the script does not make a difference (I don’t know what this has to do with autosave). The workaround when this occurs is to copy the script to the clipboard and then open and immediately save the script in a new Script Editor window.

The document “Untitled 2.scpt” could not be autosaved. C and Objective-C pointers cannot be saved in scripts. Compiling the script will reset property values and may resolve this issue.

The second reservation is that ASObjC values are not returned by Script Editor in a meaningful manner. For example, the result of a NSString is returned in Script Editor as «class ocid» id «data optr0000000000EA76A909000000» The fix for this is to coerce the NSString to text. Arrays and dictionaries can be handled similarly.

Script Editor has always done both of those things with ASObjC.

If properties or globals contain Objective-C pointers (results from the Cocoa API), the script can’t be saved because those pointers won’t be valid. The auto-save (which I do not like at all) seems a bit more aggressive, though. As mentioned, compiling will clear the persistent store, although the script needs to have been changed so that it will actually be recompiled. Another option is to save the scripts as text, although they won’t be auto-saved. Both editors tend to crash for many ASObjC errors.

Unlike Script Debugger, Script Editor wasn’t updated to show Cocoa values, so you only see their raw form. It is easy to get used to Script Debugger’s default features - the differences have caught me a few times, so I try to remember to periodically test scripts using Script Editor to check that they work there. You can also return results with a coercion to a list, which has a quirk in that all the items in the list get coerced, e.g. return {NSStringItem, NSArrayItem, NSDictionaryItem} as list. This is also handy to coerce multiple Cocoa objects passed to a handler, such as a performSelector with multiple objects.