Home > database >  How to open a Finder at the "current dir" on Mac OS in Python?
How to open a Finder at the "current dir" on Mac OS in Python?

Time:02-13

I'm aiming for my Python app to work on Windows and Mac. I'm looking to open a Finder window at the current directory (where the program is running).
The code I wrote below opens a Windows Explorer at .\ (current dir) but what is the equivalent on Mac ?

import os
import platform
#--------------

def MOpen_Explorer_Or_Finder(self,obj):

Msystem_info = platform.uname()
if(str(Msystem_info.system)=="Windows"):

    MExplorer_path = os.path.join(os.getenv('WINDIR'), 'explorer.exe')
    subprocess.run([MExplorer_path, ".\\"])

else:
    ### Or if "Darwin" (MacOS), then open Finder
    ...

CodePudding user response:

It is simply:

subprocess.run(["/usr/bin/open","."])

For more details, see the manpage for open.

  • Related