[Solved] Embed Javascript Macro in Document Module

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
peterwt
Posts: 35
Joined: Mon Apr 19, 2010 4:04 pm
Location: South Wales

[Solved] Embed Javascript Macro in Document Module

Post by peterwt »

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?
Last edited by peterwt on Sat Dec 23, 2017 7:48 pm, edited 1 time in total.
Peter
LibreOffice 4.4.1.2 on Windows 8
User avatar
robleyd
Moderator
Posts: 5079
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: Embed Javascript Macro in Document Module

Post by robleyd »

Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Embed Javascript Macro in Document Module

Post by Villeroy »

With or without APSO for Python you can simply embed the script under Script/python/ and add something like the following to META-INF/manifest.xml

Code: Select all

<manifest:file-entry manifest:media-type="" manifest:full-path="Scripts/python/XTableSQL.py"/>
    <manifest:file-entry manifest:media-type="application/binary" manifest:full-path="Scripts/python/"/>
    <manifest:file-entry manifest:media-type="application/binary" manifest:full-path="Scripts/"/>
These 3 entries declare the full path Scripts/python/XTableSQL.py plus each path element Scripts/python/ and Scripts/ as part of the document.
I would think that the same works with JavaScript and Beanshell macros as well.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Embed Javascript Macro in Document Module

Post by Villeroy »

Indeed, it works as expected. I just tried with the helloworld.js that is shipped with the office suite. I added the Script/javascript/HelloWorld/ directory with the code and another file parcel-descriptor.xml to a Writer document, added 5 entries (2 files and 3 path elements) to META/manifest.xml and a push button to call the embedded macro.
Attachments
HelloWorld.js_embedded.odt
Embedded JavaScript macro
(10.63 KiB) Downloaded 257 times
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
peterwt
Posts: 35
Joined: Mon Apr 19, 2010 4:04 pm
Location: South Wales

Re: Embed Javascript Macro in Document Module

Post by peterwt »

embedded_javascript_macro.odt
(13.29 KiB) Downloaded 235 times
Thanks Villeroy. I saw using APSO for Python that the script was put in the Python directory and the additions to manifest.xml, as you showed.

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.

I also posted this question in ask.libreoffice.org and had a similar reply from Jim K. He included an example which also shows how to call the Javascript from a Basic macro in the same document. So you can include macros in different languages in the same document. I have attached this example.
Peter
LibreOffice 4.4.1.2 on Windows 8
Post Reply