Location for storing application data on macOS

On a Mac, there are several different locations that an app can store its data, as described here:

Apple’s File System Basics

Our app creates its own database, and manages files that users create via it (i.e. users don’t choose where to save their files). That makes it sound like a good match for the Application Support folder, which is described as follows:

[quote]Use this directory to store all app data files except those associated with the user’s documents. For example, you might use this directory to store app-created data files, configuration files, templates, or other fixed or modifiable resources that are managed by the app. An app might use this directory to store a modifiable copy of resources contained initially in the app’s bundle. A game might use this directory to store new levels purchased by the user and downloaded from a server.
All content in this directory should be placed in a custom subdirectory whose name is that of your app’s bundle identifier or your company.
In iOS, the contents of this directory are backed up by iTunes and iCloud.[/quote]

That mostly worked well for us, with two exceptions:

  1. The fact that the ~/Library/ is hidden causes non-technical users problems when dealing with things like disaster recovery.

  2. Some “clean your Mac” style apps seem to think that anything in ~/Library/Application Support/ is fair game, and have then created just that kind of disaster recovery scenario [extreme headdesk]

Because of those problems, we recently moved our app’s data folder to ~/Documents/ This has been going very well for us, and completely eliminated both of those customer support headaches. Until…

Along comes macOS Sierra, and the new iCloud Desktop & Documents sync feature. That’s going to create all kinds of interesting interactions with our own data storage and synchronisation system. We also have what I think is a relatively recent addition to Apple’s documentation:

That’s nice and clear, but I’m dreading moving our app’s data folder back to ~/Library/Application Support/ because of the support headaches that it’s created in the past. I suppose we could move it to ~/Library/ourAppName/ to try and avoid problems with “clean your Mac” apps deleting things from ~/Library/Application Support/ but we still have the problem of non-technical users sometimes needing to interact with the hidden ~/Library/ directory.

So…

Does anyone else have any opinions on the most sensible location for apps to store their data?

Does anyone else who’s using ~/Library/Application Support/ have any bright ideas for coping with apps that seem to think that folder is something that they can mess around with?

Yes, do how Apple dictates to : Use ~/Library/Application Support/
Its a bit ‘take it or leave it’ approach.

We use it for all our apps and never got any issues with other apps (including Onyx, CleanmyMac, …) messing with it

imo that would be bad practice.

Thanks for the reply, Cristoph!

I know that using ~/Library/ourAppName/ feels dirty, but when I look at ~/Library/ I can see that it is at least a fairly popular choice. I wonder what reasons (other than ignorance of the guidelines) drive that decision?

If you ever want to place your app in the Mac App Store, the sandbox won’t let you mess with ~/Library. I doubt a temporary entitlement to write there would be accepted by the reviewers.

Even if for the moment you do not plan to go in the MAS, try to adhere to Apple’s guidelines. This is the right way to go. Make sure the subfolder you employ has the same name as your application ID (com.supersoftware.mygreatapp), so the system knows an app by the same ID exists.

It is not up to you to adapt to poorly behaved other software. BTW I do use CleanMyMac 3, which just released a new version for Sierra. I checked, it never touches ApplicationData. But indeed, a moron can, after the default clean, delete folders in ApplicationData (CleanMyMac shows them as “leftovers”). You can put up a strong recommendation in your software about not to delete anything by the ID of your app.

You cannot protect users from their own stupidity.

To assist users in finding that hidden ~/library/application support folder, I placed a button in my Preferences screen which says “Data Files” and which, when pushed, opens the above referenced folder.

And yet we end up trying to help them when they do something… inadvisable :wink: Seriously, thanks for the input Michel and, yes, deleting “leftovers” sounds like it might tempt some people.

Roger: yes, we’ve done something like that, which helps customers who already have the app running. The biggest problems tend to be caused by customers who have had a hard drive failure and have been given a clone of their startup disk, and then need to get into the appropriate invisible Library folder to get their data out of it. Again, something that I’m sure we can work on improving for them.

Another ‘dirty’ way to protect your ~/Library/Application Support/ is to lock it when you close/quit your app (*)
This will prevent apps like CleanmyMac removing that folder and content.

(*) don’t forget to unlock it when you start you app. :slight_smile:

dim f as FolderItem f = SpecialFolder.ApplicationData.child("yourapp") f.Locked = true

I believe into educating, and warning customers against possible mismanipulations. You can add a stern warning in your manual against precisely the leftover thing, citing explicitly CleanMyMac.

I don’t think you can really protect users against the zillion poorly designed software that pretends to fix Mac anyway.

What should be made clear to users who ruined their own stuff is that you cannot be blamed from their own gaf.

Many years ago, I had a photo shop, and routinely warned people against putting their unprocessed films in the checked luggage. Sure enough, a lady tucked them in the checked luggage on her way back from Tahiti, the vacations of her life. When the thing came back from processing unusable, she started to blame us, until I clearly reminded her of my warning. Sure, I felt for her, but she had been warned and decided to do otherwise.

[quote=288467:@Tom Catchesides]

  1. The fact that the ~/Library/ is hidden causes non-technical users problems when dealing with things like disaster recovery.[/quote]

It is very simple to see the Library folder. Hold the Option key then click the Finder’s Go menu. Or click the Finder’s Go menu and then press the Option key. Whichever way will work.

Use specialfolder.applicationData.child( ) It will store the data in the correct place, regardless if your application is Sandboxed or not.

As for iCloud, you don’t get this automatically and have to work for it.

You should never do this unless the user requests it. It’s also not possible with a Sandboxed application to do this unless the user has explicitly given your application permission to do so.

AFAIK this only affects files that haven’t been accessed within a certain time frame, and not to mention that Apple’s stingy 5GB of cloud space will attempt to charge everyone for this feature, so most will turn it off.

You should find that once you use the bundle id of your application (not the name), these apps might not remove the data all the time.

You could also simply ask the user where they’d like their data stored? If you ever Sandbox, you’d need some extra code.

[quote=288554:@Sam Rowlands]@Tom Catchesides 2) Some “clean your Mac” style apps seem to think that anything in ~/Library/Application Support/ is fair game, and have then created just that kind of disaster recovery scenario [extreme headdesk]
You should find that once you use the bundle id of your application (not the name), these apps might not remove the data all the time.[/quote]

Thanks, Sam: that’s useful to hear.