How to create new files with a python macro

Hi, I want to write a macro that will create 2 new Writer files when run. One titled “day.month.year” and the other “log day.month.year”. Today it would be 8.14.2014 and log 8.14.2014. I would prefer to do this in python but I’m open to alternatives. What is the function call / method I would use to create a new Writer file from a python script?

Hallo

Take the “hello World”-example from:
$LO_program_folder/share/scripts/python/

and store your extented script to:
$your_user_configfolder/Script/python/wathever.py

Karolus

Note, you may have to create that folder if it doesn’t exist already. You’ll also have to quit and restart LibreOffice in order for it to see your new file.

Below is a very simple example. If you place the following code in a file in the folder described above, quit and restart libre office, and then run libre office writer again, you will have two functions available for the the Tools>Macro>Run Macro option:

The function “hello_world” will place some text into the open writer document
The function “create_writer_files” will create two files in the directory specified in “path_to_files”

Notes:

  1. This will overwrite the file if it already exists.

  2. The file it creates is an empty file, while it has an odt extension, it isn’t really an odt file at this point

    def hello_world():
    XSCRIPTCONTEXT.getDocument().getText().setString(r""“Hello World!”"")

    def create_writer_files(*args):
    “”“Creates two writer files based on the date”""

    date_string = “10-10-2015”
    path_to_files = “/home/john/Documents/”

    files_to_create = []
    files_to_create.append("{0}.odt".format(date_string))
    files_to_create.append("{0}_log.odt".format(date_string))

    for each_file in files_to_create:
    full_path ="{0}/{1}".format(path_to_files, each_file)
    new_file = open(full_path, “w”)
    new_file.close()

g_exportedScripts = hello_world, create_writer_files