After spending several hours on trying to figure out how to use and debug external scripts in AppleScript bundle with Script Debugger (SD), I continue to have trouble. I have read through all of the following:
Using Script Debugger for libraries
Property values not being globally available
errOSAInternalTableOverflow Error: tips on Using Script Libraries
External debugging does not work
Script Debugger debugging-mode limitations
[Tutorial] Scripting Libraries
SD’s help page on debugging external libraries
And other posts
I am running MacOS 10.11.6 and SD 7.0.10 on an old iMac that I use for iTunes. I also tested on MacOS 10.14.6 on MBP 2016 and got same results.
Using SD, I created a new Apple Script Bundle with two files
main.scpt
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
-- The 4 statements below won't compile with main or Lib 1 saved in or out of debug mode:--
-- use Lib1 : script "Lib1" -- error "Can't get script "Lib1"" -1,728
-- use Lib1 : script "Lib1.scpt" -- error "Can't get script "Lib1.scpt"" -1,728
-- use Lib1 : script ((path to resource "Lib1.scpt" in directory "Scripts") as string) -- error "Resource not found" -192
-- property Lib1 : load script file ((path to resource "Lib1.scpt" in directory "Scripts") as string) -- error "Resource not found" -192
-- The following statement compiles and at runtime assigns value "document id "5204…"
-- but subsequently errors at /set Lib1's pNumber to 1/ in run handler unless /set Lib1 to load script file …/ is used to overwrite Lib1
-- with error "Can't make pNumber of document id … into type reference. -1,700
-- property Lib1 : document "Lib1.scpt" -- assigns value "document id "5204…"
-- this entire handler executes as expected, if Lib1.scpt is saved in not-debug mode
on run
-- the following load statement works, when "Lib1.scpt" is saved in not-debug mode
-- it does not load the script into Lib1, when "Lib1.scpt" is saved in debug mode
set Lib1 to load script file ((path to resource "Lib1.scpt" in directory "Scripts") as string)
-- the following line will compile but errors out with "Can't get the document…" -1,728, whether or not Lib1.scpt is saved in debug mode
-- set Lib1 to document ((path to resource "Lib1.scpt" in directory "Scripts") as string)
-- when Lib1.scpt is saved in debug mode and the /set Lib1 to load script file …/ above is used,
-- the next statement produces "AppleScript Execution Error" "Stack overflow." -2,706
set Lib1's pNumber to 1
-- when Lib1.scpt is saved in debug mode and /set Lib1's pNumber to 1/ immediately above is commented out,
-- the next statement produces "AppleScript Execution Error" "Can’t make pNumber of «data scpt4D617259332E3030…" -1,700
display alert "main.scpt" message "Lib1's pNumber = " & Lib1's pNumber buttons {"Cancel", "OK"} cancel button 1
set Lib1's pText to "set L1's pText"
Lib1's aHandler()
set Lib1's pNumber to (Lib1's pNumber) + 1
Lib1's aHandler()
end run
Lib1.scpt
property pText : missing value
property pNumber : 1
on aHandler()
display alert theDialog message "Lib1's pNumber = " & pNumber buttons {"Cancel", "OK"} cancel button 1
end aHandler
I don’t know why the “use” statement is not working. If I can’t get help on this, I can live with the work around of set Lib1 to load the script file …
I don’t know why I can’t use the code described in the below post to debug the library.
Using Script Debugger for libraries
I also get that Shane and others don’t like to call other libraries. I just want to get this application out. It looks like I need to break up the 2,200 lines of code to use SD. Debugging was so tedious in Script Editor. There are some other reasons that I would like to break up the code too.
Thanks,
Jonathan