Script Library vs Load Script for handlers

I used to have my Most Used handlers in three script files. Using Load Script. They also load each other.

I moved on and changed them to code signed Script Libraries as I moved from Mojave to Monterey.

I maintain around 50 scripts for 30 users. What I see with Script Libraries is:

  • If a Script library is updated, every single script using this library will have to be recompiled.
  • The script libraries are cached on users Macs, and the old version will be used. On some instances I have to reboot in Safe Mode to get the updated script/library to be loaded in the recompiled scripts.

This is now a pain to maintain and also debugging becomes difficult; “which old version of a library is REALLY in use now”?

Will reverting back to using Load Script avoid the recompile/caching thingy?
I want to just replace an updated library and get the scripts to use those.

Is there something I can execute to flush the caching of Script Libraries other than Safe Mode boot?

HĂĄvard

1 Like

That is not so. A script that calls a script library only stores the name of the library.

They are only cached while an app using them is still running.

It sounds like you’re doing something out of the ordinary. Have you tried making a simple script as a test?

This may not be related, but when editing a script where the library has change, you may need to not just compile, but you may also need to quit and relaunch Script Debugger.

I wonder if Scripts running in Fast Scripts don’t have similar issues.

No. The only thing to be aware of in Script Debugger is that if you run an open script, any libraries used by that script will be cached by AppleScript while it is open, until it is recompiled.

In older versions they do, but I think not with the latest version. But it’s something to consider when running scripts as anything other than applets.

@ShaneStanley

You’re right. In FS v3.x you no longer need to refresh a library after a saved modification.

@Havard

If the script has not been modified, you will need to “dirty” the script: type a space in any line of code (not a comment) and compile.

I am very glad to hear that this is not the intended behaviour.

Maybe I am doing it wrong? I call my script libraries this way:

use AppleScript version “2.4”
use scripting additions

use script “myLib.scptd”
property myLib : script “myLib”

set this to myLib’s test(“that”)

I know values stored in properties once upon a time were supposed to be “saved to the script across executions”, but I use signed applications and they do not change, neither are they allowed to change – otherwise the signing would be invalid, right?

Is my use of property causing this behaviour, so I should use a better way of calling them?

No need – just force compile: command-option-K.

1 Like

Yes, that approach loads the library into a property that can be stored when the script is saved. Use this:

use AppleScript version "2.4"
use scripting additions
use myLib : script "myLib"

set this to myLib's test("that")

In this way myLib is a property populated at run time.

1 Like

Right. I don’t know why I always forget this feature.
:wink:

1 Like

Thank you for your kind help Shane.

Seems property values are now stored Somewhere Else. And they seem to use path to the script for relations. Even if I replace a script with a new compiled one, the properties from the old script is still used – if run from the exact same path as where the old script was. (but not when I run the script from anywhere else). This means I can edit a script, compile and test it, but when I replace it on a users Mac it may use some old properties from the old script. Slightly confusing, but it explains a lot. Thank you for your guidance.

I have had many issues with Property values sticking around seemingly forever. Wish there was a way to clear properties on the current OS via terminal or AppleScript without having to know the property variable names.