I have found a method of configuring Scrip Libraries which saves me a lot of trouble.
Many are familar with the process of creating a script library file in ~/Library/Script Libraries.
However, there is extra work in debugging a crash in a handler in a script library file. It’s also difficult structuring a series of handlers if the handler you want in your Script Library has to call a handler or refer to a property in the main script.
I solve it like this:
At the top of my main script:
property traceHandlers : false
use U : script "Utilities_1502" -- General Utilities with no dependencies
use L : script "Loqqing_1525" -- Handlers for Logging and Reporting
use C : script "CaptureOne_1525" -- Handlers for Capture One
use G : script "GUI_1525" -- Handlers for my General User Interface
use P : script "PreferenceFile 1525" -- Handlers for Preference Files
set L's M to a reference to me
set G's M to a reference to me
set P's M to a reference to me
then in for example in GUI_1525.scpt
use U : script "Utilities_1502"
use L : script "Loqqing_1525"
property M : missing value
true
display alert "You can't run this Script Library File - there is no content in the Run Handler"
So how does all this help?
- In a handler of the Script Library I can refer to a property in the main script, like `M’s traceHandlers’ and thus control my tracehandlers feature in all my Script Libraries by a setting in the main script.
- I can call a handler in the main script from the Script Library like this
M's loadScriptDefaults()
- I can setup for debugging a handler in a script library by copying that handler to my main script.
Lets says this handler is
on initGuiGlobals2(enableFastWorkFlow)
blah
blah
blah
etc
return guiData
end initGuiGlobals2
After copying the handler to the main script, I then replace the handler in the script library by
on initGuiGlobals2(enableFastWorkFlow)
return M's initGuiGlobals2(enableFastWorkFlow)
end initGuiGlobals2
Now Script Debugger quite happily tracks the variables and states of initGuiGlobals2 as the main script executes.
When I’m done debugging, I copy my changed handler back to the Script Library
The main Caveat is don’t tell Preferences to use GUI, and GUI to use Preferences. That will result in a subtle Applescript mental breakdown that is difficult to cure.
I have been using this for about 5 years now, and except for the caveat it appears to be stable and predictable.