Ubuntu – Is it possible to add an option to the context menu in nautilus to open media in an existing VLC instance

mediamultiple instancesnautilusscriptsvlc

I've unchecked VLC's option – 'only allow one instance', since it would help simultaneous playbacks. But sometimes it is desirable to just open a new file in the already running one. Is it possible to append a script in nautilus (I don't know how) that will open the file in the already running vlc, instead of changing vlc preference or dragging and dropping methods?

Edit:
You guys might already know this, but I just found out that we could put bash scripts at "/home/.gnome2/nautilus-scripts" either in folders or not (to group them). So it's just a matter of finding out the running pid of vlc and force the file to open in it. I don't know bash scripting but if you do, please help me out here.

Best Answer

Your new edit at the question is good pointed. But I'll rephrase.

The submenu Scripts only appears in the right click on a file or directory in Nautilus once you have at least one script in the scripts directory. This script directory should be located in (if you don't have it, you should create it):

  • ~/.local/share/nautilus/scripts - for versions of Nautilus >= 3.6
  • ~/.gnome2/nautilus-scripts - for versions of Nautilus < 3.6

You can check your nautilus version from terminal using nautilus --version command.

Note: Once you place a script in your scripts directory, it's name will not necessarily appear in the scripts menu immediately. You might have to visit the scripts directory with Nautilus - which can be done using the last option in the scripts menu. Once the directory is visited, Nautilus will know about which scripts you have, and you will be able to use them.

Source: https://help.ubuntu.com/community/NautilusScriptsHowto

These being said, the following script should make the trick about you asked for your VLC:

#!/bin/bash

pid=$(pidof vlc)

## !!! if you want that only the last opened instance of vlc to be replaced 
## in case you have many instances opened, uncomment next line (delete the hash mark from the front)
#pid=$(echo $pid | cut -d ' ' -f1)

if [ "$pid" != " " ]; then
    kill $pid
fi

vlc "$@"