Python Forum
(solved) open multiple libre office files in libre office - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: (solved) open multiple libre office files in libre office (/thread-33814.html)



(solved) open multiple libre office files in libre office - lucky67 - May-29-2021

I'm a new Linux user, used to use autohotkey in windows to do this. Have installed autokey in linux and tried several ways of getting this to work using python script but getting different errors.
I want to be able to open several different libre office files (Calc and Writer) in libre office with one 'click' (task I do monthly, files are (and need to be) in different folders).
I can't even get one file to open!

open(/media/lw/8CEEXXXXAB2/1Asafedocs/PXXXXX/AXXXXX/wXXXX/WXXINUSE/TXXXXX.ods)
I have changed one folder name to remove the spaces as the 'in' was showing up as a command.
I have tried using just the open (path) command, I've also tried import os, before open (path). And Import OS, OS.open(path). Looking at the tutorials etc they all use it to open .txt or .cvs files.
I should say that I dual boot Linux and Windows and these folders are on a shared 'data' partition
So can I do this python? Am I missing out a step before I try to open the files?
Thanks for any help!


RE: absolute beginner - can I use python to do this? - BashBedlam - May-29-2021

Yes, you can use python to do this. Here is the basic script for you to modify to fit your needs. If you would like for it to be called from a desktop icon, look into .desktop files.

import subprocess

subprocess.Popen (['libreoffice', './calc/test1.xlsx'])
subprocess.Popen (['libreoffice', './docs/test2.docx'])



RE: absolute beginner - can I use python to do this? - jefsummers - May-29-2021

The above works if you want to open the .ods files in Libreoffice. If you want to open them directly in Python you need to put the path and filename in quotes. Single or double will do. open() expects a string inside, and Python will interpret what you currently have as a variable.


RE: absolute beginner - can I use python to do this? - lucky67 - May-29-2021

Thanks Bashbedlam! That seems to be trying to work now! (is trying to open libre office - I can use the first bit of the code to open libreoffice)
But it can't find the files - I have put the path in as './media/lw/'etc but the error message gives the path as /home/media/lw/etc
Do you know how I can force it look outside the 'home' partition.

(btw they are .ods /.odt files not .xlxs/.docx files but I am using the correct filenames/extensions)




(jeffsummers - I'm not really sure what the difference between a string and a variable is Blush )


RE: absolute beginner - can I use python to do this? - BashBedlam - May-29-2021

(May-29-2021, 02:17 PM)lucky67 Wrote: I have put the path in as './media/lw/'etc but the error message gives the path as /home/media/lw/etc
Do you know how I can force it look outside the 'home' partition.
The dot in ./media says to start in the current directory. To start in the root directory, where media lives, just remove the dot as in /media/lw/


RE: absolute beginner - can I use python to do this? - lucky67 - May-29-2021

Thank you so much. That's worked! So glad I asked.
I have spent hours searching for solution. I guess not wasted time as I have learned a lot and python does seem to be something it would be helpful to get to grips with.
I will have look at .desktop and also I'm already planning on trying to use the 'open libreoffice' bit to see if I could open another application I use for the same task. Something I could never get autohotkey to do.
Thanks again.