App version of script cannot find libraries - error -1728

Although my script works fine when run from a SCPT file within Script Debugger, when I save it as a .app file and try to run it on other “El Capitan”-equipped Macs. I get error

"Can’t get script “Number_functions_lib2”

which is the first library defined by Use statement in the script.

I can run the .app version on my development computer.

My understanding is that the library code is supposed to be embedded in the .app file.
However, it looks like the .app I created in Script Debugger 6.01 is expecting to see the library files on other hosts, which is not practical

If you want to embed a script library in an applet, you need to embed it yourself. Go to the Resources Pane and control-click in the Resources area, and choose New Folder. Rename the folder Script Libraries. Now drag your library file to this folder.

If you go to Script Debugger’s Help menu and choose Show AppleScript Language Guide, you can look up the section Script Libraries for details of how AppleScript searches for script libraries.

The Resources Pane did permit one to add embedded libraries - but that was in Script Debugger 5.

In Script Debugger 6, “this feature is superseded by AppleScript’s own library scripts”, according to the “Where are the libraries?” Script Debugger Help entry.

I have been struggling to rewrite my script with “Use” and “Property” statements to tell the compiler where my libraries are located. The problem is still as stated. When I create an .app file, it does not appear to know where my libraries reside.

Is there a definitive list of ALL the places appleScript will look for libraries?

In a previous post, I described how I set the environment variable OSA_LIBRARY_PATH in an environment.plist file. This variable permits storing libraries in non-default locations and tells the compiler where to look.

Per Shane (above):
Script Libraries

In the Apple language guide, it states you can store libraries in \Library\Script Libraries, or ~\Library\Script Libraries or in the folder described by OSA_LIBRARY_PATH.

So, the answer is NO. Since OSA_LIBRARY_PATH can be any folder, there can never be an inclusive list.

If you intend to distribute script as applications to others you need to embed your script libraries within the applet. This is done by doing the following:

  1. Create a folder named Script Libraries within the script’s Resources folder.
  2. Copy/add your library to the Script Libraries folder.

Your script’s bundled resources should look something like this:

Now, your script is entirely self contained. Here is my sample script for you to examine.

BundledScriptLibrary.zip (59.3 KB)

Note that is identical to how you would solve the problem using Apple’s Script Editor.

Thank you.

Just to clarify for those to follow.

Create the .app file from the .scpt.

Right-click on the .app file and select Show Package Contents

Expand Contents to show Resources

Create Script Libraries in Resources

Drag all needed library scripts into the Script Libraries folder.

I can then distribute the application and it works OK on other computers.

Could there be a way to do this through a pane or automation in future revisions?

This can all be done from within the Script Debugger UI. You can create the Script Libraries folder by right-clicking in an empty area of the Resources table, and select New Folder from the resulting contextual menu. Name the new folder Script Libraries. You can then drag libraries from the Finder into the the Script Libraries folder you’ve created in Script Debugger.

Or, you can do as you describe, and reveal the contents of the script app and manipulate the Resources folder using the Finder.

Shane just posted on our blog about this very topic.

Thanks. It took me a while to to find the Resources Tab but, thanks to your description, the process is clear.

Would there be a problem having a Script Libraries folder included by default? The +/- technique of adding libraries used in previous versions was very handy.

I added to this thread because we solved the problem in APP but something has changed so that it does not recognize libraries in SCPT.

When I loaded the original SCPT file in Script Debugger 6.0.3, any attempt to compile results in
"AppleScript Compile Error - Can’t get script “Number_functions_lib2”

When I look in the Resources window, it is empty. If I load the last APP version of the file, I see all the Libraries referenced properly in the Resources Window.

How do I get the SCPT to recognize the libraries? When I right-click on the empty Resources pane, the menu shows:
Paste, Font, Spelling and Grammar, Substitutions, Transformation, Speech and Layout Orientation.

What is does not show is “New Folder”

This problem has brought my development to a halt.

Please help.

You can only embed libraries in script bundles, which means .app and .scptd files. You will need to save your .scpt files as .scptd bundles.

I don’t want to embed the library scripts; i just want them recognized so I can write, run and edit the script.

Apparently the Applescript compiler or the version Script Debugger 6 uses ignores OSA_LIBRARY_PATH no matter if it is installed in the environment,plist using lauchctl setenv. That was the technique that worked before, even though it required disabling SIP. I hate to use a standard location because I use revision control which cannot reach those folders, I’ve moved them to ~/library/Script Libraries for the time being, just to prove they still work. However,.this means that I cannot restore my files set to a previous point, which is one of the primary advantages of revision control.

I’m sorry, I don’t follow. You said:

That means copies of the libraries are embedded in the applet.

Then you said:

All that relates to embedding libraries within script bundles.

What do you mean by “before” – before what?

“Before” would be in July when I started this thread.

Anyway, I was able to set the path in /Libary/Launchagents/environment.plist and now it works just fine.

Thanks for considering my problem.