[Solved] Can't find place to create a python macro

Keyboard macros or custom scripts

[Solved] Can't find place to create a python macro

Postby jason1984 » Tue Dec 11, 2018 5:33 pm

Hello, I did lots of search but couldn't find steps to create a python macro for a linux system.

Under the Libreoffice-Tools-macro menu I find :
1. run macro
I can run "Hello world" python macro just fine but can't create one.
2. edit macro
I can only find many macros written only in Basic language. If I try to write my python macro start with "import uno" in it I get syntax error.
3. manage macro
All the 'create', 'edit" buttons are grayed out.

So, where do I create my own python macro? Thanks.
Last edited by jason1984 on Wed Dec 12, 2018 6:31 pm, edited 2 times in total.
Libreoffice 6.1.3.2 on openSUSE Leap 15.1
jason1984
 
Posts: 6
Joined: Tue Dec 11, 2018 5:20 pm

Re: Can't find place to create a python macro

Postby FJCC » Tue Dec 11, 2018 6:05 pm

You can write Python macros with your favorite text editor and save them in the folder
/home/username/.openoffice/4/user/Scripts/python
using the .py file name extension. They will then appear in the MyMacros section of the OpenOffice macro organizer.
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7230
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Can't find place to create a python macro

Postby Villeroy » Tue Dec 11, 2018 7:44 pm

With LibreOffice the script path might be ~/.config/libreoffice/4/user/Scripts/python/

Have a look at Tools>Options>Paths
The default paths for templates, galery etc. indicates the profile folder.

See also: https://extensions.libreoffice.org/exte ... thon/1-0.0
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26980
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Can't find place to create a python macro

Postby jason1984 » Wed Dec 12, 2018 4:19 am

Thank you for helping.

Under my user folder it is:
Code: Select all   Expand viewCollapse view
~/.config/libreoffice/4/user> ls
autocorr  autotext  backup  basic  config  database  extensions  gallery  pack  psprint  registrymodifications.xcu  store  uno_packages  wordbook


There's no ./Scripts/Python there. Manually creating one won't make it appear in Macros.

On the other hand, I notice that in Libreoffice-Tools-Options-Path, I have
Classification pointing to /usr/lib64/libreoffice/program/../share/classification/example.xml,
which led me to find /usr/lib64/libreoffice/share/Scripts/Python.

It seems I somehow need to let Libreoffice be aware of python scripts under my home folder so I don't always need root privilege to create a python script in /usr/....Python?
Libreoffice 6.1.3.2 on openSUSE Leap 15.1
jason1984
 
Posts: 6
Joined: Tue Dec 11, 2018 5:20 pm

Re: Can't find place to create a python macro

Postby John_Ha » Wed Dec 12, 2018 2:08 pm

See Spell checker "red wriggly lines" - beta test fix for AOO for detailed instructions on how to install a python macro.

Showing that a problem has been solved helps others searching so, if your problem is now solved, please view your first post in this thread and click the Edit button (top right in the post) and add [Solved] in front of the subject.
AOO 4.1.6, Windows 7 Home 64 bit

See the Writer Manual, the Writer FAQ, the Writer Tutorials and the Writer guide.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
John_Ha
Volunteer
 
Posts: 6740
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Can't find place to create a python macro

Postby Villeroy » Wed Dec 12, 2018 4:58 pm

download/file.php?id=36285 is an example macro distributed as a Writer document with an installer written in Basic. The path and file name is stored in a user field.
The attached template lets you create such an installer. Open the template, double-click the user field, modify the field value, replace the place holder with your source code and save the document in a trusted directory where document macros are allowed to be run (Tools>Options>Security>MacroSecurity>Trusted Sources).
The macro appends the user field value to the profile path, creates the directory if needed and saves the document as plain text which saves the plain text body without the frame and button.
Attachments
ScriptInstaller.ott
Writer template with user field to save plain text files in the user profile (e.g. macros in languages other than StarBasic)
(18.08 KiB) Downloaded 36 times
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26980
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved]Can't find place to create a python macro

Postby jason1984 » Wed Dec 12, 2018 6:35 pm

The problem seems to be needing ..../Scripts/python instead of "Python".
Libreoffice 6.1.3.2 on openSUSE Leap 15.1
jason1984
 
Posts: 6
Joined: Tue Dec 11, 2018 5:20 pm


Return to OpenOffice Basic, Python, BeanShell, JavaScript

Who is online

Users browsing this forum: No registered users and 2 guests