Hello!
I wrote a macro using python (pyUno) and have to start it from the
terminal. In the documentation, I found the following way to do that:
libreoffice /home/me/desktop/myEmptyFile.odt
"vnd.sun.star.script:HelloWorld.py$helloWorldPython?language=Python&location=user"
Where the file HelloWorld.py is in the following dir:
/home/me/.libreoffice/3/user/Scripts/python/
And the file contains the following function as you can see in the code
below: helloWorldPython()
But it doesn't work, I get a ScriptingFrameworkException in from the
file pythonscript.py in line 896 which should load the python scripts...
I think, this works for openoffice, but not for libreoffice, at least in
my case. I finally found a workaround by calling a basic macro from the
terminal, which itself calls my Python function. But this isn't good
style, there must be another solution!? Can anybody help me with the
correct shell command? Or confirm the error when trying to execute the
python code directly from the terminal. My system: Ubuntu 11.04, 64bit.
Thanks a lot in advance!
Aaron
Content of HelloWorld.py
import uno
def helloWorldPython( ):
context = uno.getComponentContext()
smgr = context.ServiceManager
desktop =
smgr.createInstanceWithContext("com.sun.star.frame.Desktop", context)
document = desktop.loadComponentFromURL("private:factory/swriter",
"_blank", 0, ())
cursor = document.Text.createTextCursor()
document.Text.insertString(cursor, "Hello world.", 0)
################################################################
Content of the basic macro which finally executed the python function
succesfull from the terminal with the following command (soffice
"macro:///Standard.Module3.CallPython"):
Sub CallPython
oFactory =
createUnoService("com.sun.star.script.provider.MasterScriptProviderFactory")
oProvider = oFactory.createScriptProvider("")
oScript =
oProvider.getScript("vnd.sun.star.script:HelloWorld.py$helloWorldPython?language=Python&location=user")
oScript.Invoke(Array(), Array(), Array())
end sub
--
Unsubscribe instructions: E-mail to users+help@libreoffice.org
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/www/users/
All messages sent to this list will be publicly archived and cannot be deleted
Context
- [libreoffice-users] Start libreoffice together with python script from terminal · Aaron Richiger
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.