python open new terminal code example

Example 1: how to open file explorer in python

import os
import subprocess
FILEBROWSER_PATH = os.path.join(os.getenv('WINDIR'), 'explorer.exe')

def explore(path):
    # explorer would choke on forward slashes
    path = os.path.normpath(path)

    if os.path.isdir(path):
        subprocess.run([FILEBROWSER_PATH, path])
    elif os.path.isfile(path):
        subprocess.run([FILEBROWSER_PATH, '/select,', os.path.normpath(path)])

Example 2: launch bash script from application mac without opening terminal

mkdir -p ./myapp.app/Contents/MacOS

Example 3: launch bash script from application mac without opening terminal

#!/bin/bash

Tags:

Misc Example