Persistent properties lost on some scripts run from script menu

I’m having two issues with the script below. First, if I run it from the scripts menu it forgets the property values (you can tell because it resets the table position to its default, and takes longer to run). If run from an SD window it remembers the properties.

The other issue is intermittent. If I run it from an SD window, and have it open a few files when I click “Finish” sometimes all of the SD tool bar buttons or SD menus are deactivated. Can’t do anything with SD. When it gets in this state I have to activate another app (not Chrome, usually the Finder) and go back to SD.

–> Script Debugger 7.0 (7A37)
–> Script Debugger 6.0.8 (6A221)
–> Mac OS 10.13.3 (17D47)


use framework "Foundation"
use AppleScript version "2.4"
use scripting additions
use script "Myriad Tables Lib"

-->  Script Debugger 7.0 (7A35)
property sdVersionForHelp : "Script Debugger-7.0-7A35" -- -

property currentVersionInfo : ""
property debugging : false -- logging
property fullScreenWindowBounds : {}
property helpFileDisplayList : {}
property helpFileList : {}
property helpTextFolder : ""
property htmlResultsPage : ""
property lastSearch : "Script Debugger Help"
property lastSelectedRow : {0}
property logFile : ""
property logInfo : ""
property previousFinds : {}
property previousSearchCount : 20 -- how many previous searches to remember
property previousSearches : {}
property screenFraction : 3 --how much screen should results take
property sdAppId : "com.latenightsw.ScriptDebugger7"
property sdHelpDir : "sd7help"
property sdHelpFileLocation : ""
property sdLocation : ""
property searchDate : ""
property searchResultsFolder : ""
property slugDate : ""
property startingTime : ""
property tableInitPosition : {300.0, 25.0, 390.0, 740.0}
property workFlowFolder : ""

on run
   
   set currentSDVersion to SDVersion()
   if helpFileDisplayList is {} then
      set lastSelectedRow to {0}
      
      set sdHelpFileLocation to HelpFileLocation()
      LocateHelpFiles(sdHelpFileLocation)
      --Sets helpFileList
      
      set AppleScript's text item delimiters to {"<Title>", "</Title>"}
      
      repeat with thisHelpFile in helpFileList
         set thisHelpFile to thisHelpFile as item
         set helpFileTitle to read thisHelpFile
         set helpFileTitle to paragraph 1 of text item 2 of helpFileTitle
         set the end of helpFileDisplayList to {helpFileTitle, "", thisHelpFile as item}
      end repeat
   end if
   
   set markedFiles to {}
   repeat
      set {chosenItem, chosenFile, buttonNumber} to DisplayHelpTable()
      if buttonNumber is 2 then
         set the end of markedFiles to item chosenItem of helpFileDisplayList
         set item 2 of item chosenItem of helpFileDisplayList to "S"
      else
         set item 2 of item chosenItem of helpFileDisplayList to "√"
         set fileToDisplay to item 3 of item 1 of chosenFile
         my DisplayHelpFile(fileToDisplay)
      end if
   end repeat
end run



on DisplayHelpFile(htmlDisplayFile)
   if fullScreenWindowBounds is {} then -- First run only, learns size of screen
      tell application "Finder" to set fullScreenWindowBounds to (bounds of desktop's window)
      set {windowLeft, windowTop, windowRight, windowBottom} to fullScreenWindowBounds
      set {windowLeft, windowTop} to {25, 23}
      set fullScreenWindowBounds to {windowLeft, windowTop, windowRight, windowBottom}
   end if
   
   tell application "System Events"
      set helpFileURL to URL of (htmlDisplayFile as alias)
   end tell
   
   tell application "Google Chrome"
      set helpWindow to make new window
      set URL of tab 1 of helpWindow to helpFileURL
      tell helpWindow
         set {windowLeft, windowTop, windowRight, windowBottom} to fullScreenWindowBounds
         set bounds to {(windowRight / screenFraction) * (screenFraction - 1), windowTop, windowRight, windowBottom}
      end tell
      activate
   end tell
end DisplayHelpFile

on DisplayHelpTable()
   set nextRow to item 1 of lastSelectedRow
   set nextRow to nextRow + 1
   if nextRow > (count of helpFileDisplayList) then
      set nextRow to 1
   end if
   set helpFileTable to make new table with data helpFileDisplayList ¬
      with title ¬
      "Help Files" with prompt ¬
      "Select which file to open" multiple selections allowed false ¬
      can add and delete false ¬
      column headings {"Help File Topic", "Seen"} ¬
      row numbering false ¬
      initially selected rows {nextRow} ¬
      empty selection allowed false ¬
      multiple lines allowed false ¬
      with double click means OK
   
   modify table helpFileTable ¬
      OK button name ¬
      "View" OK button is default true ¬
      cancel button name ¬
      "Finish" extra button name ¬
      "Save this one" highlighted rows {} ¬
      row dragging false ¬
      column reordering false ¬
      hidden cancel button false ¬
      initial position tableInitPosition
   
   set tableResults to display table helpFileTable ¬
      with extended results
   set helpFileDisplayList to values returned of tableResults
   set lastSelectedRow to rows selected of tableResults
   set valueSelected to values selected of tableResults
   set buttonNumber to button number of tableResults
   
   set {tableX, tableY, tableW, TableH} to final position of tableResults
   set TablePosition to {tableX, tableY, tableW, TableH}
   if tableX < 20 then set tableX to 20
   if tableY < 20 then set tableY to 20
   set tableInitPosition to {tableX, tableY, tableW, TableH}
   
   return {lastSelectedRow, valueSelected, buttonNumber}
end DisplayHelpTable
-------------

on HelpFileLocation()
   --on HelpFileLocation(mainFileName, appId, HelpFileDirectory)
   --set helpFilePath to (path to resource mainFileName in bundle (path to appId) in directory HelpFileDirectory)
   set helpFilePath to (path to resource "toc.html" in bundle (path to application id (sdAppId as text)) in directory sdHelpDir)
   tell application "Finder"
      set sdHelpFileLocaton to container of helpFilePath as alias
      if debugging then open sdHelpFileLocaton
   end tell
   return sdHelpFileLocaton
end HelpFileLocation

on LocateHelpFiles(sdHelpFileLocaton)
   set helpFileList to {}
   ProcessAFolder(sdHelpFileLocaton)
   
end LocateHelpFiles



on SDVersion()
   set mustUpdate to false
   set sdPath to (path to application id sdAppId)
   if sdPath is not sdLocation then
      set sdLocation to sdPath
      set sdVersionForHelp to "" --forces an update
   end if
   set sdPath to POSIX path of sdPath
   set sdPlist to quoted form of (sdPath & "Contents/Info.plist")
   set _cmd to "/usr/libexec/PlistBuddy -c Print:CFBundleShortVersionString -c Print:CFBundleVersion " & sdPlist
   set currentVersionInfo to paragraphs of (do shell script _cmd)
   set currentVersionInfo to "Script Debugger " & item 1 of currentVersionInfo & " (" & item 2 of currentVersionInfo & ")"
   
   set AppleScript's text item delimiters to {"-"}
   set currentVersionInfo to words of currentVersionInfo as text
   return currentVersionInfo
end SDVersion

-------------

on ProcessAFolder(thisFolder)
   tell application "Finder"
      set myHelpFiles to (every file of thisFolder whose name extension is "html") as alias list
      set myFolders to every folder of thisFolder as alias list
   end tell
   set helpFileList to helpFileList & myHelpFiles
   repeat with aFolder in myFolders
      my ProcessAFolder(aFolder)
   end repeat
end ProcessAFolder