Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

So i like to use mplayer for multimedia in GNU/Linux.

But one problem i have, is that i can't make my file-managers open audio files in it because they just play "in the background."

What i tried to accomplish with this script, was to open mplayer with a terminal "terminator -e 'mplayer {}'" when given an audio file. So that i could control the playback (pause/play). And open it without the terminal when given a video file.

But naturally- since I'm posting here- it doesn't work. It doesn't spew out error messages or anything, it's just that nothing happens. I also tried prefixing "export DISPLAY=:0" (even though i should have seen some errors for that to be necessary.)

It's weird because this command, when executed in a terminal. Works fine and does what you'd expect.

terminator -e "mplayer /path/to/file"

I'm completely stumped by this. Here's the source:

## A small script for opening files in mplayer with file browsers.

import sys, os, re, subprocess

usage = """
      {} <filename>

ERROR = "{}: Error: ".format(sys.argv[0])
TERMINAL = "terminator -e "

get_extension = re.compile(r"\..*$")

## Common audio formats
audio = [
        , '.flac'
        , '.au'
        , '.m4a'
        , '.ogg'
        , '.wav'

## Common video formats
video = [
        , '.3gp'
        , '.avi'
        , '.flv'
        , '.mkv'
        , '.mov'

## Automatic error-checking for indexing lists.
def getL(xs, x):
        return xs[x]
    except: return False

def main():
    if len(sys.argv) > 1:
        extension = getL(get_extension.findall(sys.argv[1]), 0)
        ## Return 1 if the extension doesn't match anything in video or audio.
        do = lambda: 1
        if not extension:
            print(ERROR+"No file extension found")
            return 1
        if extension in video:
            do = lambda: os.system('mplayer {}'.format(sys.argv[1]))
        if extension in audio:
            do = lambda: os.system(TERMINAL+"'mplayer {}'".format(sys.argv[1]))
            ## Maybe if i add a & to the end of it... No.
            # do = os.system(TERMINAL+"'mplayer {}' &".format(sys.argv[1]))
            ## Maybe subprocess works... No.
            # do = lambda: subprocess.call(["terminator", '-e', '"mplayer {}"'.format(sys.argv[1])])
        return do()
    return 1

if __name__ == '__main__':
share|improve this question
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.