Create APSO Toolbar Icon

After installing the APSO Extension it is configured under Tools, Customise, Keyboard: LibreOffice, Shortcut Keys - Alt+Shift+F11 service:apso.python.script.organiser.impl?execute

Under My Macros, apso.oxt, tools it only lists the console Function, not execute. How is APSO attached to a LibreOffice Toolbar icon? Preferred icon is C:/Program%20Files/LibreOffice/help/media/icon-themes/cmd/32/scriptorganizer.svg

My Basic macro does the same as Ctrl+Shift+F11.
Tthe translation into Python:

def Trigger_Apso(*args):
     s = "apso.python.script.organizer.impl"
     smgr = uno.getComponentContext().ServiceManager
     oService = smgr.createInstance(s)

No need for desktop or current document. Just let the global service manager instanciate service “apso.python.script.organizer.impl”. This works from any component including the office start screen.

btw: how can I define a code block here? [Solved]


You can specify a string of three characters ``` before and after the code.
It is also possible to try to specify the language in the first line of code:

1 Like

Thank you… Is this documented somewhere?

Asked at Where is the help on using Discourse, that is easily discoverable by users? :slight_smile:

1 Like

How can Trigger_Apso be pushed back into the apso.oxt file (unpacking/packing zip is understood)? [btw It needs to import uno.]

I tried inserting Trigger_Apso before the last line in, then adding function name to last line and removing last line. It’s basically the same code before the trigger command except it uses XSCRIPTCONTEXT instead of uno.

def console(*args, **kwargs):
    # we need to load apso before import statement
    ctx = XSCRIPTCONTEXT.getComponentContext()
    # now we can use apso_utils library
    from apso_utils import console
    kwargs.setdefault('loc', {})
    kwargs['loc'].setdefault('XSCRIPTCONTEXT', XSCRIPTCONTEXT)
    return console(**kwargs)

g_exportedScripts = console,

calls sources/python/pythonpath/ · master · Jean-Marc Zambon / apso · GitLab

APSO is an extension. It is not a macro.
You can add a toolbar to the extension package. I know, this is ridiculously difficult but searching for the URL to call the service I found “service:apso.python.script.organizer.impl?execute” in Accelerators.xcu.
In a Basic macro you can trigger that service like this:

Sub Trigger_Apso()
oService = createUnoService(s)
End Sub

I use to call APSO via Ctrl+Shift+F11 analog to Ctrl+F11 calling the Basic organizer.


Thank you, that works and gets me going. Until I learn more about UNO I’ll take your word for it.
The APSO shortcut key is Ctrl+Shift+F11 as you say but I probably won’t remember it.
For toolbar button:

  1. Create macro: Tools, Macro, Edit, and paste it into a module.
  2. Create toolbar button: Tools, Customise, Toolbars, Category Macros - select macro and position it, Modify, Change icon, Select icon, OK

Now, we’re not going to launch a python IDE with Basic are we? Unlike Basic the context needs to be set up (Python : Programming with Python):

# launch APSO - Alternative Python Script Organiser
import uno

def context():
    # set global variables for context
    global desktop
    global model
    global active_sheet
    # get the doc from the scripting context 
    desktop = XSCRIPTCONTEXT.getDesktop()
    model = desktop.getCurrentComponent()
    active_sheet = model.CurrentController.ActiveSheet
def trigger_apso(*args):
    # call function context()

    s = "apso.python.script.organizer.impl"
    #oService = createUnoService(s)
    ctx = uno.getComponentContext()
    smgr = ctx.getServiceManager()
    o_service = smgr.createInstanceWithContext(s, ctx)

Comments on launcher code welcome.

the name of context is somehow ugly and misleading, the whole Function is completly unnecessary in this context, and in any case if possible you should NOT use global


No macro needed. Add a toolbar to the extension. I wrote the macro only because I was too lazy to write tons of tricky XML.
Adding the macro to the extension would add a similar level of complexity and the result would not include any visible GUI element.
Extension development is a nightmare (to me at least). I avoid nifty GUI elements. If you want to learn more about this, you should be very familiar with the product and read some tutorials.

Copied from another extension:

<oor:component-data xmlns:oor="" xmlns:xs="" oor:name="Addons" oor:package="org.openoffice.Office">

  <node oor:name="AddonUI">
<-- some other UI elements here -->

        <node oor:name="OfficeToolBar">
            <node oor:name="" oor:op="replace">
                <node oor:name="m1" oor:op="replace">
                    <prop oor:name="Context" oor:type="xs:string">
                    <prop oor:name="URL" oor:type="xs:string">
                    <prop oor:name="ImageIdentifier" oor:type="xs:string">
                        <value />
                    <prop oor:name="Title" oor:type="xs:string">
                        <value xml:lang="en">SmART gallery</value>
                        <value xml:lang="hu">SmART galéria</value>
                    <prop oor:name="ControlType" oor:type="xs:string">
                    <prop oor:name="Target" oor:type="xs:string">

        <node oor:name="Images">
            <node oor:name="" oor:op="replace">
                <prop oor:name="URL" oor:type="xs:string">
                <node oor:name="UserDefinedImages">
                    <prop oor:name="ImageSmallURL">
                    <prop oor:name="ImageBigURL">

The XLM is a nice answer but I’m actually more interested in learning about macro programming and uno [after having tried a couple of tutorials and checking the docs] than this specific solution. It doesn’t look straightforward in the APSO example I provided above.

[Tutorial] Introduction into object inspection with MRI

P.S. I forgot to mention that the XML UI configuration belongs to file Addon.xcu of an extension package.