Better way to use Script Function libraries please

Hi,

I want to ask if there is a better way to use Script Function libraries?

Until yet I'm using this Script Function technique:

@script jscript

eval(includeFile("M:\\Data\\Config\\DoMusic", "Config.js"));
eval(includeFile(DOMUSIC_MAIN_PATH, "FixReleaseAfterRipping.js"));

// OnClick
function OnClick(clickData)
{
  // Get all selected directories
  var enumDirs = new Enumerator(clickData.func.sourcetab.selected_dirs);
  // Call main program
  new FixReleaseAfterRipping(enumDirs);
  // Return ok
  return true;
}

// Library Loader
function includeFile(libpath, filename)
{
  var fso = new ActiveXObject("Scripting.FileSystemObject");
  var fileref = libpath + "\\" + filename;
  var fileStream = fso.openTextFile(fileref);
  var fileData = fileStream.readAll();
  fileStream.Close();
  return fileData;
}

In every launcher I've to store the function "includeFile". This global function is then known in any class I use (to load other classes with eval).

This works really fine - also if child classes with be loaded multiple times by different parent classes.

But it doesn't really look nice and I don't like the hardcoded things ...

I few weeks ago I've read about XYExplorer and clicked on the release notes and saw this:

"Scripting with Include. The new include statement enables you to include function libraries or whatever other files into the executing script."

See http://www.xyplorer.com/release_15.40.php under "Scripting with Include" I've found:

include "math.inc";

Maybe we can specify 1-x root path for a library and DO also searches in sub dirs (organization!)

Wouldn't it be nice to also have a better way in DO?

You can use .WSF packages to bundle multiple files into a single script add-in. (This is a feature of Windows Scripting, not specific to Opus.) That works with script add-ins but not buttons that contain scripts, but you have a script add-in which adds a command and then run the command from a button.

If you want to do it similar to how you're doing things already, and the problem is the hardcoded paths, then you don't need to hardcode the paths. You're in a scripting language and can evaluate the paths any way you need to. I'm not sure what the paths you're trying to access are or how you'd prefer to use them, but using path aliases might be a solution.

Hmm ... doesn't really sound "Keep it simple" too me :confused: In a year or less I've forgotten how it works.

Finally a code something like this would be great:

@script jscript

include "FixReleaseAfterRipping.js";

// OnClick
function OnClick(clickData)
{
  // Get all selected directories
  var enumDirs = new Enumerator(clickData.func.sourcetab.selected_dirs);
  // Call main program
  new FixReleaseAfterRipping(enumDirs);
  // Return ok
  return true;
}

The include line replaces the complete function "includeFile". DOpus parses for the "include" line and loads the .js file from (multiple) specified path => .js library.

However - only an idea to have it easier & better to read.

Folder Alias is a good idea - never used them. :wink:

What does that give you that you don't have already?

I think it's time to come up with an actual example of "how to use windows script components".

I put something together that could give you a start:
Windows Script Components - Quick-HowTo: HowTo: Create a function-library with Windows Script Components (WSC)

Thanks a lot tbone! Will read & try it later today (hopefully).