There is a lot of information on how to RUN a Python macro in LibreOffice, but I couldn't find any on how to RECORD a Python macro (a bit like the old VBA or the new JavaScript macro recording in Excel)... I find recording useful for doing very basic things without having to check the LO API, so I wonder if this is possible and how.
1 Answers
The recorder in LibreOffice generates dispatcher code in Basic. This is generally not a good way to learn either Basic or Python macro programming, but it can handle some tasks if you are trying to avoid having to write code and don't care that it's cumbersome. (A few tasks are best handled by the dispatcher, such as copy and paste, but that's not really relevant for your question).
The good thing is that dispatcher code can easily be translated into languages such as Python. So what you need to do is:
- Learn how to do a dispatcher call in Python, for example https://wiki.documentfoundation.org/Macros/Python_Guide/Useful_functions#Call_dispatch.
- Record the macro in Basic. The UNO calls will be the same no matter what the language.
- Convert the dispatcher calls into a Python macro. For example, instead of Basic
Array()
use Python tuples()
.
Alternatively, MRI can generate Python-UNO code. Details are at https://github.com/hanya/MRI/wiki/Code. This generates API code which is better than dispatcher code. However MRI isn't really a recorder; instead you have to select the UNO calls.

- 12,824
- 2
- 22
- 51
-
1Nice answer. It's also worth noting that the dispatch recorder must be explicitly enabled in Tools...Options...LibreOffice...Advanced. – bfris Oct 20 '21 at 19:08