Tuesday, September 17, 2019

#1 2019-08-22 01:29:17 pm

mcsprodart
Member
Registered: 2013-03-09
Posts: 5

Using library from parent app/bundle

Can anyone suggest a way to Use Library in a .scpt/.scptd being run from an enclosing bundle/app? Ive tried putting it in either bundles script libraries but still its not found for some reason when I test.

Example: App with Use Library “Test” run script somescript.scpt/somescript.scptd with Use Library “Test”

It will only run if I put the “Test” library into ~/Library/Script Libraries not if I put in SomeApp.app/Contents/Resources/Script Libraries


Filed under: use library

Offline

 

#2 2019-08-22 09:49:02 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 526

Re: Using library from parent app/bundle

I am not sure, but I think you should use script library from app's bundle with other way:

You app (main script) should load script library into variable and then use this variable as a reference to the library. And to get location of this library into the bundle is better using (path to me) & "/Contents/Resources/Script Libraries/.....". Or, using path to resources command.

Otherwise, you have to force the user of your application to copy the built-in libraries to the computer folder ~/Library/Script Libraries.

Last edited by KniazidisR (2019-08-22 10:04:15 pm)


macOS Mojave -- version 10.14.4
Safari -- version 12.1

Online

 

#3 2019-08-22 10:00:18 pm

mcsprodart
Member
Registered: 2013-03-09
Posts: 5

Re: Using library from parent app/bundle

Yeah I agree. It works well with my libraries themselves, but Shane has solved alot of the Mojave threading issues with the Dialog Toolkit Plus and Use "Dialog Toolkit Plus" has to be in all of the places I use it forcing the sub-scripts to be bundles. Sounds simple enough but it gets complicated when calling Dialogs from subroutines in my libraries.

I researched specifying location of library and couldn't find much other then a suggestion to save as Framework and thats a learning curve I dont have alot of time for.

Any advice is appreciated!

Last edited by mcsprodart (2019-08-22 10:01:02 pm)

Offline

 

#4 2019-08-22 10:14:57 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 526

Re: Using library from parent app/bundle

Calling handlers is simple. Example:

Applescript:

set numberLibrary to (load script file "NumberLib.scpt")

tell numberLibrary
   factorial(10) -- calling one handler
   areaOfCircle from 12 -- calling other handler
end tell

A suggestion to save as Framework is the same thing: you force the user to install your Framework.

Last edited by KniazidisR (2019-08-22 10:24:14 pm)


macOS Mojave -- version 10.14.4
Safari -- version 12.1

Online

 

#5 2019-08-23 02:58:12 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 5003

Re: Using library from parent app/bundle

mcsprodart wrote:

Example: App with Use Library “Test” run script somescript.scpt/somescript.scptd with Use Library “Test”


Hi.

What code are you actually using? The 'use' syntax for a library with the file name "Test.scpt" or "Test.scptd" is:

Applescript:

use myLib : script "Test" -- If you'll be calling the library's handlers.
-- Or just:
use script "Test" -- If the library defines its own terminology.

It will only run if I put the “Test” library into ~/Library/Script Libraries not if I put in SomeApp.app/Contents/Resources/Script Libraries


Do you mean that it won't compile, or that you're trying to run the library?


NG

Offline

 

#6 2019-08-23 05:30:29 am

mcsprodart
Member
Registered: 2013-03-09
Posts: 5

Re: Using library from parent app/bundle

Sorry for the confusion. I am using both, however the issue I was having was with:

use script "Test" -- the library defines its own terminology.

When I ran the code in Script Debugger, It was requiring it to be in ~/Library/Script Libraries. I had hoped saving as scpt and having in the bundle of the parent app would resolve this or that there would be a solution of indicating where the library was in the plist or through another option.

Offline

 

#7 2019-08-23 06:44:03 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 5003

Re: Using library from parent app/bundle

I see. I'm not experiencing any problem myself in either Script Debugger or Script Editor, although it's a bit of a chicken-or-egg situation setting it up. You can't compile the 'use' command until the library's been added to the script bundle and there's no bundle until you've compiled and saved the script!

Using this code as a simple library …

Applescript:

on doIt()
   say "You have successfully called me."
end doIt

… and this as a prospective script bundle or applet containing it …

Applescript:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use myLib : script "My Lib"

tell myLib to doIt()

beep

… you have to save the library somewhere convenient, say your desktop, as "My Lib.scpt" and write the main script either without the 'use myLib …' line or with it commented out. Then compile the script and save it in the appropriate bundle or application form. Once that's done, you can add the library to the bundle and recompile the main script with the 'use myLib …' line included/enabled.

Script Debugger:
As far as I can see, with Script Debugger, you have to prepare the library by putting it in a folder called "Script Libraries" in your convenient place. Then click the button whose icon looks like a cool box in SD's tool bar. This should open a panel of gumpf which includes a pane called "Resources". If you click the "+" icon at the bottom of this, you'll get a choose file or folder dialog in which you navigate to and select your prepared "Script Libraries" folder. SD copies the folder and its contents to the main script's "Resources" folder and you can now recompile the script with all the relevant lines and resave it.

Script Editor:
With Script Editor, you click the "Bundle Contents" button in the tool bar, which reveals a similar panel. You can either drag your "Script Libraries" folder into the "Resources" pane or create one there using the cog button menu and drag the library script onto its icon. Recompile with the 'use' line and save.

It works for me.  hmm


NG

Offline

 

#8 2019-08-23 06:18:41 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5894

Re: Using library from parent app/bundle

Nigel Garvey wrote:

it's a bit of a chicken-or-egg situation setting it up. You can't compile the 'use' command until the library's been added to the script bundle and there's no bundle until you've compiled and saved the script!



FYI, if you start the document in Script Debugger by using File -> New Script from Template... (or the tab equivalent) and choose either an application or a script bundle (there's a check box), the subsequent Untitled document comes with a bundle, so you don't have to save first.

If you click the "+" icon at the bottom of this, you'll get a choose file or folder dialog in which you navigate to and select your prepared "Script Libraries" folder. SD copies the folder and its contents to the main script's "Resources" folder



You can also control-click in the Resources area and choose Add Script Libraries Folder, then just drag your library script over the created folder.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#9 2019-08-24 02:06:50 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 5003

Re: Using library from parent app/bundle

Shane Stanley wrote:

FYI, if you start the document in Script Debugger by using File -> New Script from Template... (or the tab equivalent) and choose either an application or a script bundle (there's a check box), the subsequent Untitled document comes with a bundle, so you don't have to save first.


Ah. Thanks, Shane. It shows how little I use script bundles myself.  roll


NG

Offline

 

#10 2019-08-25 09:08:41 am

TedW
Member
Registered: 2005-11-02
Posts: 51

Re: Using library from parent app/bundle

Nigel Garvey wrote:

it's a bit of a chicken-or-egg situation setting it up. You can't compile the 'use' command until the library's been added to the script bundle and there's no bundle until you've compiled and saved the script!



Just to add to what Shane said, in Script Editor — once you've saved a script as a script bundle or script application — there's a toolbar button on the top right of the script window that shows the bundle contents (or you can type ⌘-0 to get the same thing). You can drag/drop any files or folders you like straight in.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)