I added saving preferences with PrefsStorageLib, and I am having all sorts of problems. For a while, the problems could not be replicated in a short example, but today I can replicate them. I have two computers, both running Catalina, and they show the same behavior: when I run this simple applet (below), sometimes I get an error that “The ‘prepare storage’ command was unable to initialize user defaults. Unknown error. … error (-2700)” and other times the program crashes with a stack/heap collision. This only happens with the “on open” handler, and only when I run the program as an applet, the bug never shows up when I run the applet from within Script Debugger.
Here is the strange thing: I was able to solve the problem by saving the file as text, and then compiling it with Script Editor. So I am currently thinking that this is some obscure bug in Script Debugger, but I really don’t understand.
Here is the applet
use AppleScript version "2.5"
use scripting additions
use script "PrefsStorageLib" version "1.1.0"
property pTemplate : missing value
property pTemplateModDate : missing value
property pFieldNames : missing value
on open droppedItems
prepare storage for domain "com.alanharper.test2" without write lock
--set pFieldNames to value for key "pFieldNames"
--set pTemplateModDate to value for key "pTemplateModDate"
--set pTemplate to alias for key "pTemplate"
display dialog ((length of droppedItems) as text) & " items dropped"
open
The “without write lock” is because I thought that might solve the problem. It seems to make no difference.