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.
vnd.sun.star.script:HelloWorld4.helloworld4.js?language=JavaScript&location=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.