Problem Editing/Executing Macro from Tools>Macros>Organise Python Scripts

I am on Ubuntu 22.10 and LO 7.5.4.2 and have written my first script in Geany.

But when I try to go to run the script in Tools>Macros>OrganisePython Scripts, I can only find the name of the file as a module (Tool_Fill)…and not as an editable or executable script (Tool_Fill.py). What have I missed please?

But Tool_Fill.py…is already in there! This is so confusing…I must be missing some key step!

A macro is wrapped in a routine definition (Python def, Basic Sub).

store you scripts into …/Scripts/python/ thereis no need for a another subfolder!!

Hallo
As @Villeroy said before, Libreoffice »see« only code proper wrapped into function-definitions:

from pathlib import Path
def test(*_):
    doc_folder = Path.home() / "Documents"
    source_path = doc_folder / "current_sheet.ods"
    target_path = doc_folder / "Tool_Test.ods"

    source_uri = source_path.as_uri()
    target_uri = target_path.as_uri()

    desktop = XSCRIPTCONTEXT.getDesktop()

    source_doc = desktop.loadComponentFromURL(source_uri, "_blank", 0, (),)
    target_doc = desktop.loadComponentFromURL(target_uri, "_blank", 0, (),)


    source_sheet = source_doc.Sheets[0]
    target_sheet = target_doc.Sheets[0]
    target_sheet["A1"].Value = source_sheet["A1"].Value 

    for row_index in range(1, 9):
        target_sheet[row_index, 1].Value = source_sheet[row_index, 1].Value

Thank you so much for that…it is a great help and I really appreciate it!

Sorry to bother you again, could you explain

from pathlib import Path

I have not come across it before and can’t quite grasp from searching, what it’s function is.

And perhaps

Hi again, sorry!

I tried to follow your template as per below. It compiles with no problem and it executes with no errors.

But when I open Tool_Test, no data has been transferred…what have i done wrong this time?

Thank you for your time and help, I really appreciate it.

This is what I get when I run the Macro in LO.

Unsupported URL <file:///home/yodap/Documents/Targets/Prospectives/Clothing>: “type detection failed” at ./framework/source/loadenv/loadenv.cxx:189 (Error during invoking function Tool_Fill in module file:///home/yodap/.config/libreoffice/4/user/Scripts/python/PythonLibray/Tool_Fill.py (<class ‘uno.com.sun.star.lang.IllegalArgumentException’>: Unsupported URL <file:///home/yodap/Documents/Targets/Prospectives/Clothing>: “type detection failed” at ./framework/source/loadenv/loadenv.cxx:189
File “/usr/lib/libreoffice/program/pythonscript.py”, line 915, in invoke
ret = self.func( *args )
^^^^^^^^^^^^^^^^^^
File “/home/yodap/.config/libreoffice/4/user/Scripts/python/PythonLibray/Tool_Fill.py”, line 12, in Tool_Fill
source_doc = desktop.loadComponentFromURL(source_uri, “nike.ods”, 0, (),)

Here is the url of the Nike file: /home/yodap/Documents/Targets/Prospectives/Clothing/

image