user1176501
user1176501

Reputation:

open file in finder or explorer on linux or unix

I don't have any Mac OSx or Linux machine, but I want to implement the functionality like opening an explorer from a selected file path.

for example

import subprocess
subprocess.Popen('explorer "E://temp//"')

the above code opens windows explorer for a specified path, how to do it for Mac or Linux ?

Upvotes: 0

Views: 1737

Answers (2)

Matteo Italia
Matteo Italia

Reputation: 126787

You can use the desktop package (in particular its open function) to take care of the OS-specific details. It should work on Linux, Windows and OS X.

If you want to do this on your own, instead, you can:

  • launch xdg-open on Linux;
  • launch open on OS X;
  • use os.startfile on Windows.

Upvotes: 1

mgilson
mgilson

Reputation: 309929

It looks like you can use xdg-open on linux and open on OS-X.

e.g.

subprocess.Popen(['xdg-open','/home/me/otherdir'])

or

subprocess.Popen(['open','/home/me/otherdir'])

Upvotes: 3

Related Questions