Python Forum
(solved) open multiple libre office files in libre office
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
(solved) open multiple libre office files in libre office
#1
Question 
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!
Reply
#2
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'])
Reply
#3
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.
Reply
#4
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 )
Reply
#5
(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/
Reply
#6
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Right way to open files with different encodings? Winfried 2 158 Yesterday, 05:50 PM
Last Post: snippsat
  Open files in an existing window instead of new Kostov 2 299 Apr-13-2024, 07:22 AM
Last Post: Kostov
  Using a script to open multiple shells? SuchUmami 9 497 Apr-01-2024, 10:04 AM
Last Post: Gribouillis
  python convert multiple files to multiple lists MCL169 6 1,549 Nov-25-2023, 05:31 AM
Last Post: Iqratech
  open python files in other drive akbarza 1 690 Aug-24-2023, 01:23 PM
Last Post: deanhystad
  splitting file into multiple files by searching for string AlphaInc 2 899 Jul-01-2023, 10:35 PM
Last Post: Pedroski55
Question [solved] compressing files with python. SpongeB0B 1 649 May-26-2023, 03:33 PM
Last Post: SpongeB0B
  Help replacing word in Mutiple files. (SOLVED) mm309d 0 836 Mar-21-2023, 03:43 AM
Last Post: mm309d
  Merging multiple csv files with same X,Y,Z in each Auz_Pete 3 1,164 Feb-21-2023, 04:21 AM
Last Post: Auz_Pete
  unittest generates multiple files for each of my test case, how do I change to 1 file zsousa 0 965 Feb-15-2023, 05:34 PM
Last Post: zsousa

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020