Get Firefox profile directory with Python (Linux and Windows)

Piece of code used in Basico ( module) to get the default user’s Firefox profile directory.

This profile must have the SAP Passport imported in the Certificate store.

import sys

def get_firefox_profile_dir():
    if sys.platform in ['linux', 'linux2']:
        import subprocess
        cmd = "ls -d /home/$USER/.mozilla/firefox/*.default/"
        p = subprocess.Popen([cmd], shell=True, stdout=subprocess.PIPE)
        FF_PRF_DIR = p.communicate()[0][0:-2]
        FF_PRF_DIR_DEFAULT = str(FF_PRF_DIR,'utf-8')
    elif sys.platform == 'win32':
        import os
        import glob
        APPDATA = os.getenv('APPDATA')
        FF_PRF_DIR = "%s\\Mozilla\\Firefox\\Profiles\\" % APPDATA
        PATTERN = FF_PRF_DIR + "*default*"
        FF_PRF_DIR_DEFAULT = glob.glob(PATTERN)[0]


print (get_firefox_profile_dir())

2 thoughts on “Get Firefox profile directory with Python (Linux and Windows)

Leave a Reply to Sinan Cancel reply

Your email address will not be published. Required fields are marked *