Find path to Application Support directory in python in MacOS

Viewed 110

I've been working on a mac app for a long time now, under the assumption that everyone has their Application Support folder located at /Users/[user_name]/Library/Application Support. However, I recently learned this is not true. I need something I can do in python to get the path to the Application Support directory on anyone's computer. Everything I've seen so far has been very outdated with respect to python. The only leads I have are some PyPi packages, PyCocoa and pyobjc-framework-Cocoa. I intend for this to work across several recent OS versions (one person has Monterey, one has Catalina, one has Big Sur, I have Mojave), and it seems that the path to the Application Support folder has changed across versions. What is the accepted way to find this folder on any computer?

Thanks!

1 Answers

Might be a bit slow, but the os library has a walk function which may help. You could loop through the most likely places i.e., $HOME, etc. Then read through the subfolders...something like this should identify the directories - obviously, you will need to check them against your expectation.

[x[0] for x in os.walk(top-directory)]
Related