Here’s my version of the same script (FWIW). See if this generates the same errors (Also requires PrefsStorageLib). This doesn’t do the search, just displays the dialog.
use framework "Foundation"
use script "PrefsStorageLib" version "1.1.0"
use script "Dialog Toolkit Plus" version "1.1.3"
use scripting additions
property lastSearchOption : ""
property lastSearchString : ""
property lastReplaceString : ""
property lastMatchWords : ""
property lastCaseSensitive : ""
property lastSearchScope : ""
PersistentVariables()
repeat
set {searchOption, searchString, replaceString, matchWords, caseSensitive, searchScope} to SearchDialog()
set {lastSearchOption, lastSearchString, lastReplaceString, lastMatchWords, lastCaseSensitive, lastSearchScope} ¬
to {searchOption, searchString, replaceString, matchWords, caseSensitive, searchScope}
StorePersistentValues()
end repeat
on SearchDialog()
if lastSearchOption is ("") then set lastSearchOption to ("Replace All")
try
set viewWidth to 335
set spacer to 10
set fieldIndent to (max width for labels {"Search:", "Replace:"}) + 5
set allControls to {}
set {theButtons, buttonWidth} to ¬
create buttons {"Exit Search", "Find Next", "Replace & Find", "Replace All"} ¬
cancel button 1 default button lastSearchOption
if buttonWidth > viewWidth then set viewWidth to buttonWidth
set {selectionAllMatrix, theTop} to create matrix {"Search All", "Search Selection"} ¬
left inset fieldIndent ¬
bottom 0 ¬
max width viewWidth - 80 ¬
arranged vertically false ¬
initial choice lastSearchScope
set the beginning of allControls to selectionAllMatrix
set theBottom to theTop + spacer
set {wordMatchCheckbox, unusedTop, wordWidth} to create checkbox ("Match Words") ¬
left inset fieldIndent ¬
bottom theBottom ¬
max width (viewWidth / 3) - 12 ¬
initial state lastMatchWords
set the beginning of allControls to wordMatchCheckbox
set {caseSensitiveCheckbox, theTop, caseWidth} to create checkbox ("Consider Case") ¬
left inset (fieldIndent + wordWidth + 58) ¬
bottom theBottom ¬
max width (viewWidth / 3) ¬
initial state lastCaseSensitive
set the beginning of allControls to caseSensitiveCheckbox
set {replaceField, replaceLabel, theTop, fieldIndent} to create side labeled field (lastSearchString) ¬
placeholder text (" replace with...") left inset 3 bottom (theTop + spacer) ¬
total width viewWidth label text ("Replace:") field left fieldIndent
set the beginning of allControls to replaceField
set the end of allControls to replaceLabel
set {searchField, searchLabel, theTop, fieldIndent} to create side labeled field (lastReplaceString) ¬
placeholder text (" search for...") left inset 3 bottom (theTop + spacer) ¬
total width viewWidth label text ("Search:") field left fieldIndent
set the beginning of allControls to searchField
set the end of allControls to searchLabel
set {searchOption, controlsResults} to ¬
display enhanced window ("Search and Replace") ¬
buttons theButtons acc view width viewWidth ¬
acc view height theTop acc view controls allControls ¬
initial position {} without align cancel button
set {searchString, replaceString, wordMatch, caseSensitive, searchScope} to controlsResults
return {searchOption, searchString, replaceString, wordMatch, caseSensitive, searchScope}
on error errMsg number errNum partial result partialError
local partialError
partialError
if errNum ≠ -128 then display dialog errMsg & ("Error number: ") & errNum
error errMsg number errNum
end try
end SearchDialog
on PersistentVariables()
prepare storage for (path to me)
RetreiveStoredValues()
end PersistentVariables
on StorePersistentValues()
assign value lastSearchOption to key "lastSearchOption"
assign value lastSearchString to key "lastSearchString"
assign value lastReplaceString to key "lastReplaceString"
assign value lastMatchWords to key "lastMatchWords"
assign value lastCaseSensitive to key "lastCaseSensitive"
assign value lastSearchScope to key "lastSearchScope"
end StorePersistentValues
on RetreiveStoredValues()
set my lastSearchOption to value for key "lastSearchOption"
set my lastSearchString to value for key "lastSearchString"
set my lastReplaceString to value for key "lastReplaceString"
set my lastMatchWords to value for key "lastMatchWords"
set my lastCaseSensitive to value for key "lastCaseSensitive"
set my lastSearchScope to value for key "lastSearchScope"
end RetreiveStoredValues