Python Forum
Open files in an existing window instead of new
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Open files in an existing window instead of new
#1
OS: Linux Mint 21.3
Python version: 3

I’m transcribing .mp3 audio files. To make the job easier, I’ve bound the following script in AutoKey to a hotkey.

It allows for opening whatever text is highlighted as a file in the VLC media player:

import subprocess

audiofile = clipboard.get_selection()
subprocess.run(
    [
        "vlc",
        "/mnt/SSD/Audio/{}.mp3".format(audiofile),
    ],
)
The script runs fine. However, every command to run VLC opens a new window, cluttering the system.

How can I open a file in an existing VLC instance whenever the script runs? subprocess.run doesn’t seem to be right for this.
Reply
#2
(Apr-12-2024, 09:58 AM)Kostov Wrote: How can I open a file in an existing VLC instance whenever the script runs? subprocess.run doesn’t seem to be right for this.
I don't think the problem is with subprocess.run. I t is rather a problem with the vlc command. You could perhaps try the --one-instance option
import subprocess
 
audiofile = clipboard.get_selection()
subprocess.run(
    [
        "vlc",
        "--one-instance",
        "/mnt/SSD/Audio/{}.mp3".format(audiofile),
    ],
)
« We can solve any problem by introducing an extra level of indirection »
Reply
#3
Thank you, Gribouillis!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Right way to open files with different encodings? Winfried 2 272 Apr-23-2024, 05:50 PM
Last Post: snippsat
  Is there a way to call and focus any popup window outside of the main window app? Valjean 6 1,844 Oct-02-2023, 04:11 PM
Last Post: deanhystad
  how to open a popup window in tkinter with entry,label and button lunacy90 1 913 Sep-01-2023, 12:07 AM
Last Post: lunacy90
  open python files in other drive akbarza 1 731 Aug-24-2023, 01:23 PM
Last Post: deanhystad
  Open a new window does not work Nietzsche 4 1,142 Jun-14-2023, 08:52 AM
Last Post: Nietzsche
  Add\insert header row existing csv files mg24 0 736 Oct-05-2022, 06:11 AM
Last Post: mg24
  Pyspark Window: perform sum over a window with specific conditions Shena76 0 1,196 Jun-13-2022, 08:59 AM
Last Post: Shena76
Sad Selenium: can't open a new window after clicking a button and I don't know why noahverner1995 0 1,997 Jan-22-2022, 09:55 AM
Last Post: noahverner1995
  How to open/load image .tiff files > 2 GB ? hobbyist 1 2,481 Aug-19-2021, 12:50 AM
Last Post: Larz60+
  Open and read multiple text files and match words kozaizsvemira 3 6,790 Jul-07-2021, 11:27 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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