Information wants to be free...

Easy File Selection

Here is a trick to let you easily select a file "graphically" for a console based application, when launched from a menu in a window manager. It uses Python and two modules that are delivered with the standard distribution.

The following example launches the "mplayer" media player with a selected file:

#!/usr/bin/python

import subprocess
import tkFileDialog

file = tkFileDialog.askopenfilename()
if len(file) > 0:
    subprocess.call(["mplayer", file])
          


Instead of launching the application directly, create a script like this and point the menu entry towards that instead.

Topic: Configuration, by Kjetil @ 04/04-2012, Article Link