Say I have a directory with about 100 .rtf
files I edit with LibreOffice Writer.
I desire that all files in that directory will have the exact same basic rich text styling-directives, for example:
* font-family: Ubuntu # All text in all files is now Ubuntu;
* font-size: 12px # All text in all files is now 12px big;
h1: 28px # All h1's are now 28px big;
if font-size: 18px {make it 22px} # All text with font-size 18px is now 22px;
And so forth… So, basically I want to change all files at once. Is such "bulk-styling" possible?
Maybe it's possible with the CLI somehow?
Best Answer
Use Libreoffice tools instead of CLI
When all you have are command line tools everything looks like a command line problem. I've decided to write this answer using LibreOffice macros:
.rtf
(Rich Text Format) Writer document file.Create test data
Create two or more files containing:
Create script
~/Downloads/copy-rtf.sh
containing:Mark as executable using
*.rtf
files will run against~/Downloads
directory.cd ~/Downloads
and run./copy-rtf.sh
The Downloads directory is used because:
~/Downloads
/tmp/
directory which may not persist across reboots.Run macro in headless environment
Using this Stack Exchange answer invoke Libreoffice Writer from the command line and pass it a global macro name to execute:
The above answer may not work so another method can be tried:
Install Java Runtime Environment
To run macros you need Java Runtime Environment (JRE) installed. The developer's web page has instructions for downloading and installing manually.
However this AU Q&A: https://askubuntu.com/a/728153/307523 suggests it is as simple as:
I tried the AU Q&A method and after the first step of adding the PPA a splash screen appears with additional information. The most helpful is a link to setting up JRE 8 on Debian systems.
The third step of installing JRE 8 requires you to use Tab and Enter to accept the License Agreement. Your machine will pause for a few minutes during the heaviest part of the installation routine.
Now open LibreOffice and select Tools -> Options -> LibreOffice -> Advanced and setup this screen:
Click the options for:
LibreOffice Writer Macro
The macro will read through the entire document and:
The macro will save document and exit Libreoffice Writer.
Turn off Dialog
Do a file save and this dialog comes up:
Turn this message off as show in the screen. The macro may not run properly if this option is on.
Macro contents
I spent a few days attempting to record a macro using "Tools" -> "Macros" -> "Record Macro" -> "Basic". At first it seemed promising but the recorded macro had inconsistent behavior and had to be abandoned for a hand written basic macro. A found help in Stack Overflow for an expert there to help me with the basic basic coding. Here is the result: