Extension run on LibreOffice startup?

Extension run on LibreOffice startup?

Is it possible to have an extension run python code on start of LibreOffice without any extra configuration?

My goal to to write and extension that contains a python module that also includes sub-modules.
This would be for the OooDev module.

I am envisioning users being able to write/run macros using OooDev by simply importing as if the ooo-dev-tools was pip installed.

# example import in macro
from ooodev.utils.lo import Lo
from ooodev.office.calc import Calc
...

I know that the ooo-dev-tools package can be pip installed, I wrote some guides on this. However, it is not always reliable and more confusing to end user then installing an extension.

What I need to do is to have an extension include itself on the python path when LibreOffice starts.

I noticed that the MRI and the APSO extension have a pythonpath sub-directory. When the APSO console is run it includes it’s pythonpath in python’s sys.path.

The MRI pythonpath does not show up in the sys.path until it is run, as in starting MRI from the menu.

I am the author of OooDev however I have no real experience with extensions at this time, I spent all day reading and experimenting.

I am figuring that it would be best to find out is my goal is even possible before I learn the rest.

Turns out the answer is yes it can be done.
I did this for the OOO Development Tools Extension

The trick is to create a job that subscribes the OnStartApp event.
See my jobs.xcu file for an example.

Here is an event list.

  • OnStartApp
  • OnCloseApp
  • OnCreate
  • OnNew
  • OnLoadFinished
  • OnLoad
  • OnPrepareUnload
  • OnUnload
  • OnSave
  • OnSaveDone
  • OnSaveFailed
  • OnSaveAs
  • OnSaveAsDone
  • OnSaveAsFailed
  • OnCopyTo
  • OnCopyToDone
  • OnCopyToFailed
  • OnFocus
  • OnUnfocus
  • OnPrint
  • OnViewCreated
  • OnPrepareViewClosing
  • OnViewClosed
  • OnModifyChanged
  • OnTitleChanged
  • OnVisAreaChanged
  • OnModeChanged
  • OnStorageChanged
  • OnPageCountChange
  • OnMailMerge
  • OnMailMergeFinished
  • OnFieldMerge
  • OnFieldMergeFinished
  • OnLayoutFinished
1 Like

Note: The oor:op= must be set to fuse (oor:op="fuse") to allow other events to be raised.

oor:op=“replace” would block other events with the same name from being raised.

<node oor:name="Events">
  <node oor:name="OnStartApp" oor:op="fuse">
    <node oor:name="JobList">
      <node oor:name="OooDevRunnerJob" oor:op="fuse" />
    </node>
  </node>
</node>