Can't Get "use script" statement to work (Script Library)

Can’t Get “use script” statement to work
I’m running Yosemite 10.10.5

My understanding from the AppleScript Language Guide is that this statement:

would enable you to use handlers/functions in the script library without any further reference.
IOW, you could use them just as if they were in the same script file you’re calling them from.

I’ve spent hours researching, reading, and testing, and I can’t make it work.
Has anyone else been able to make this work? If so, please share your secrets. :confused:

When it gets to the statement where it calls my function in my script library, I get this error msg:

Here’s my code:

use AppleScript -- added this out of desperation ... didn't help

use scripting additions -- read some forum posts that this was needed if you have any other "use" statements.

use myLib : script "TestLib" -- Stored in my ~/Library/Script Libraries folder

--  use script "TestLib"

--use script "TestLib" with importing  -- Tried this, didn't help

--- THIS WORKS -----
display dialog "hello world"

--- THIS WORKS ---
tell myLib
	myHello("Test using lib")
end tell

--- THIS FAILS ---
myHello("TEST 2 without a tell")

(*------- ERROR MSG ---------
Script Error
«script» doesn't understand the "myHello" message

Here’s my extremely simple Script Library file:

## My AS Lib:  TestLib.scpt in ~/Library/Script Libraries folder

on myHello(pMsg)
	display alert pMsg
end myHello

The “use statement” is hard to find. It is listed under the Commands Reference, but the links don’t seem to work very well. So, here it is:

Not quite. If the script library contains an .sdef file that defines terminology for its handlers, then you can use that terminology without further reference to the library. But for normal handlers, you still need to address the library.

For example, my BridgePlus script library contains some commands defined in an .sdef file, as well as normal handlers:

use theLib : script "BridgePlus"

framework version -- defined in the lib
-->	"1.3.1"
set newList to theLib's colsToRowsIn:{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}} -- a normal handler in the lib
-->	{{1, 4, 7}, {2, 5, 8}, {3, 6, 9}}

OK, thanks. That was very helpful. :smiley:

This works:

I watched a video about creating the .sdef – looks quite tedious.
Are there any tools to create the .sdef from the script file?

That’s right.

The only AppleScript-related one I know of is part of ASObjC Explorer. I think it’s pretty good, but then I’m the author of it…

Thanks. I’ll take a look at it.

Will it work for JXA script libraries also?

No – AppleScript only.