File access on a MAC

In other threads, I have seen it recommended to put files used by my application in the folder

SpecialFolder.ApplicationData.Child(“MyAppFolder”)

I have an SQLite database that is used by my application. I am using AppWrapper, and I am putting this database in the resources folder. This file is marked read only unluss the user moves the app to another folder. How can I create an install to put the file in the proper place? My app is signed and notarized,

Create the SQLite database in code in the final location.

Its best practice to use the bundle identifier of the application, as this allows the OS to understand that this folder is for your application.

static mSupportfolder as folderitem = specialFolder.applicationData.child( "com.ohanaware.appWrapper4RG2" )
if mSupportFolder.exists = false then mSupportFolder.createAsFolder

To test and install the database, I’d use something like the following.

Dim appDataFile as folderitem = mSupportFolder.child( "My Great Application.sqlite" )
if appDataFile.exists = false then
  Dim dataTemplateFile as folderitem = specialFolder.resource( "TemplateFile.sqlite" )
  dataTemplateFile.copyTo appDataFile
end if
2 Likes

Why ?

Apple guidelines. Convention.

Application Support Contains all app-specific data and support files. These are the files that your app creates and manages on behalf of the user and can include files that contain user data.

By convention, all of these items should be put in a subdirectory whose name matches the bundle identifier of the app. For example, if your app is named MyApp and has the bundle identifier com.example.MyApp, you would put your app’s user-specific data files and resources in the ~/Library/Application Support/com.example.MyApp/ directory. Your app is responsible for creating this directory as needed.

Resources required by the app to run must be placed inside the app bundle itself.

2 Likes

Thank you Rick.

But the OS have nothing to do with these files (of course, I follow the development guidelines); it reads nothing nor write…

image

3 Likes

If your App is Sandboxed, macOS will already hide you app away. I use the equivalent of:

Var f As FolderItem = SpecialFolder.ApplicationData.Child(“MyAppNameOrIdentifier”)
Var SourceDB As FolderItem = "path to database in Resources folder"

If Not f.Exist Then f.CreateAsFolder
f = f.Child(“Databases”)
If Not f.Exist Then f.CreateAsFolder
SourceDB.CopyFileTo(f)
'Open the SourceDB database in the ApplicationData folder
…