Embed Javascript Macro in Document Module

You can create a Library Module in a Document to hold Basic macros, and using the APSO extension the same for Python macros.

Is it possible to do the same fot Javascript macros and if so how?

EDITED 20/12/17

@jimk I saw using APSO for Python that the script was put in the Python directory and the additions to manifest.xml.

I noticed looking at the scripts supplied with LO that the beanshell, java, and javascript scripts were in a directory for each script. The directory had the script and a parcel-descriptor.xml file. I wasn’t sure if the parcel-descriptor had to be included in the manifest.xml. The example you included shows all i needed, including calling the javascript from Basic.

Cross-posted to [Solved] Embed Javascript Macro in Document Module (View topic) • Apache OpenOffice Community Forum.

Here is a working example: embedded_javascript_macro.odt. Unzip to view or change the macro files.

Be sure to put the .js file inside its own module (directory), along with parcel-descriptor.xml. In the attached example, the file is located at embedded_javascript_macro/Scripts/javascript/HelloWorld4/helloworld4.js.

The additional lines to manifest.xml are as follows:

 <manifest:file-entry manifest:full-path="Scripts/javascript/HelloWorld4/helloworld4.js" manifest:media-type=""/>
 <manifest:file-entry manifest:full-path="Scripts/javascript/HelloWorld4/parcel-descriptor.xml" manifest:media-type=""/>
 <manifest:file-entry manifest:full-path="Scripts/javascript/HelloWorld4/" manifest:media-type="application/binary"/>
 <manifest:file-entry manifest:full-path="Scripts/javascript/" manifest:media-type="application/binary"/>
 <manifest:file-entry manifest:full-path="Scripts/" manifest:media-type="application/binary"/>

The following Script URI works, as seen in Call_Macro in the attached document.


LibreOffice needs to be restarted to see JavaScript macros.

As mentioned a few days ago, I do not recommend the built-in LibreOffice JavaScript engine, except perhaps for testing. According to the devguide, JavaScript support is only a prototype, although possibly the documentation is out of date in this regard.

If people are serious about using JavaScript, then an extension similar to APSO could be written. Actually, the majority of the APSO code should work for JavaScript. It would simply require adding extra JavaScript features such as generating parcel-descriptor.xml. Not too hard, if someone were to (unlike me) want to see JavaScript more fully embraced by the LibreOffice community.

Thank you @jimk, just what I wanted. Please see my edited question.