Hi, I’m a Script Debugger (SD) holdout and new here because I was overwhelmed by the UI and now I’m willing to try learning it again after getting most of my scripts (hundreds) to where I want them to be and I’m sick of Script Editor app (SE) crashing each time I need to close a tab.
I’m building an AppleScript library that allows me (hopefully I can share it with the public soon when it becomes stable enough to run using SD because it is probably what most of the serious AppleScripters use to write AppleScripts, just my assumption).
My issue with SD is when I re-run some AppleScripts, I get this undefined error where a library reference, which I usually declare globally with the intention to reuse, gain some optimization and make it accessible inside handlers, whenever I re-run a script without making any changes. So it works fine as long as I change the script. I don’t have this problem when using SE but like I’ve said, I’m tired of that app crashing each time I need to close a tab. Can someone please help me understand what is going on and why am I experiencing this error? The issue only happens on some scripts, not all of them. So it could be something I need to tweak for those affected.
Here’s how I design my scripts.
I have a highly re-used script I call std.applescript which takes care of importing other scripts. std.applescript contains this handler:
on import(moduleName)
init()
set scriptObj to script moduleName
try
if not initialized of scriptObj then
scriptObj's init()
end if
end try
scriptObj
end import
On a client script, I would have something structured such as:
set std to script "std"
set logger to std's import("logger")'s new("hello")
logger's info("Hello AppleScript Core!")
The above script works fine, even on re-run.
However on another script:
set std to script "std"
set inspector to std's import("app-inspector")'s new()
set savedAppDetail to inspector's getSavedAppDetails() -- Fails here with the error "mapLib is not defined"
The app-inspector.applescript would contain:
global std, mapLib
property initialized : false
on init()
if initialized of me then return
set initialized of me to true
set std to script "std"
set mapLib to std's import("map")
...
So the mapLib is indeed used inside the getSavedAppDetails handler, but why is it not accessible during the subsequent run given it is declared globally and should have been initialized inside the init during the import?
I appreciate any feedback on how I can improve my posting so that it is clear and helpful to others. Thank you in advance.