Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding "~/Library/Application Support" from C++?

Tags:

c++

macos

I've written a GTKmm application and I'm trying to create some OS X enhancements. I'd like to store my configuration file in the Application Support/myApp folder, however, I can't figure out the proper way to locate this folder.

I've tried looking through the Core Foundation library (that I'm using to get my myApp.app path) but I can't find anything.

like image 976
Brandon Avatar asked Feb 25 '11 22:02

Brandon


People also ask

How do I find Library application support on Mac?

To access the Application Support folder, perform the following task: Open Finder from Dock. Navigate to the Menu bar and click Go. Next, press the Option key and select Library to open the Library folder.

Can I delete Application Support folder on Mac?

The Application Support folder holds files that some apps need to run. While there are a number of files you could delete here, it's best to be careful.

Where can I find applications?

Swipe up from the bottom of your screen to the top. If you get All Apps , tap it. Tap the app that you want to open.


1 Answers

Proper way to do it in C/C++:

#include <CoreServices/CoreServices.h>

FSRef ref;
OSType folderType = kApplicationSupportFolderType;
char path[PATH_MAX];

FSFindFolder( kUserDomain, folderType, kCreateFolder, &ref );

FSRefMakePath( &ref, (UInt8*)&path, PATH_MAX );

// You now have ~/Library/Application Support stored in 'path'

Naturally, those are very old APIs and their use is no longer recommended by Apple. Despite that it gets the job done if you want to avoid Objective-C completely in your codebase.

like image 54
Julio Gorgé Avatar answered Oct 21 '22 00:10

Julio Gorgé