10.14+: where to store the preferences file ?

Hi folks,

I have a working app for years that stores its prefs file in the Library/Preferences folder of the user.
since 10.14 (last update we had on a client mac) when I launch the app it’s ok, but at the second launch the app quits immediately
without any message, no dialog box and nothing in the console.
if I delete this prefs file, the app can be launched again. until the next launch.

I suppose there is a better place for this pref file, in recent mac os . but where is it better ?
do I have to use different places depending on the system version ?

thanks for your lights.

You can use SpecialFolder.ApplicationData.Child("com.your.app") on Mac and Windows platforms. On Linux, I believe the custom is to prefix that with a dot to make it invisible SpecialFolder.ApplicationData.Child(".com.your.app").

I store a settings.json in there.

Are you getting the FolderItem from the Xojo system SpecialFolder.Preferences or hardcoded?
Any console logged errors?

As always: show us your code. Are you using allowed APIs or did you roll your own?

[quote=480675:@Rick Araujo]Are you getting the FolderItem from the Xojo system SpecialFolder.Preferences or hardcoded?
Any console logged errors?[/quote]

Apple hasn’t wanted developers to manually access SpecialFolder.Preferences for years.

I use SpecialFolder.Preferences actually. I will try ApplicationData.

Me, changed this as well some years ago. ApplicationData works very fine.

to add to this topic for future readers :
there is a blog entry by Paul about this , with code example.
https://blog.xojo.com/2014/01/27/saving-preferences/

Mac OS X 10.9 was the first version of the Mac OS that started to have issues when manually accessing files in this location.

Yes, please do. Files in the Preferences folder on the macOS should not be manually modified, if you want to store your preferences here, you should use API (as Apple do caching and other opaque things with files in this folder). NSUSerDefaults or CFPreferences are the recommended API.

If you do decide to use API, it does make this much cleaner for small amounts of data as you are not responsible for de-serializing the file. So you can simply request variables when you need them with a minor performance hit (when compared to preloaded properties). You can store most basic types in the macOS preferences including dictionaries (NSDictionaries).

Otherwise you should follow what @Tim Parnell says.

[quote=480674:@Tim Parnell]You can use SpecialFolder.ApplicationData.Child(“com.your.app”) on Mac and Windows platforms. On Linux, I believe the custom is to prefix that with a dot to make it invisible SpecialFolder.ApplicationData.Child(“.com.your.app”).

I store a settings.json in there.[/quote]

Perhaps Preferences folder should be removed from SpecialFolder, as while it’s technically correct and probably still usable on other platforms, it’s a pitfall for the macOS platform.

I was thinking so, but before writing this, I checked the docs and read the Special.Preferences part for macOS: as amazed as I was, it was noted:

On macOS, use SpecialFolder.ApplicationData to save your own files or directly call CFPreferences to save preferences files here.

All I can say is: it is my fault if in some (old) project, I use Preferences in macOS ;).

What can be done is a warning at compile time.