views:

887

answers:

3

I want to open a folder window, in the appropriate file manager, from within a cross-platform (windows/mac/linux) Python application.

On OSX, I can open a window in the finder with

os.system('open "%s"' % foldername)

and on Windows with

os.startfile(foldername)

What about unix/linux? Is there a standard way to do this or do I have to special case gnome/kde/etc and manually run the appropriate application (nautilus/konqueror/etc)?

This looks like something that could be specified by the freedesktop.org folks (a python module, similar to webbrowser, would also be nice!).

A: 

this would probably have to be done manually, or have as a config item since there are many file managers that users may want to use. Providing a way for command options as well.

There might be an function that launches the defaults for kde or gnome in their respective toolkits but I haven't had reason to look for them.

Tanj
A: 

You're going to have to do this based on the running window manager. OSX and Windows have a (defacto) standard way because there is only one choice.

You shouldn't need to specify the exact filemanager application, though, this should be possible to do through the wm. I know Gnome does, and it's important to do this in KDE since there are two possible file managers (Konqueror/Dolphin) that may be in use.

I agree that this would be a good thing for freedesktop.org to standardize, although I doubt it will happen unless someone steps up and volunteers to do it.


EDIT: I wasn't aware of xdg-open. Good to know!

Adam Lassek
+7  A: 

os.system('xdg-open "%s"' % foldername)

xdg-open can be used for files/urls also

pixelbeat