Where are the application preference files location on Mac - macos

I am having a hard time finding from where my application is picking up its window dock and location settings. I removed the related plist files and folders from the following directories:
[USER]/Library/Preferences
[USER]/Library/Preferences/By Host
[USER]/Library/Caches
[USER]/Library/Saved Application State
But the old window settings are retained when I launch the application. The application is using CFPreferencesCopyValue method to read preference values:
::CFPreferencesCopyValue("Toolbars:MyTools:Application", "kCFPreferencesCurrentApplication", kCFPreferencesCurrentUser, kCFPreferencesCurrentHost);
I am not very familiar with Mac's preferences mechanism. Can someone explain what could be happening here? Thanks

This problem hit me recently so I thought I'd post the answer here belatedly.
When you delete the preferences on a Mac (plist file) make sure you clear the cached preferences otherwise Java programs can keep working with the cached settings.
You can:
after you have deleted your plist file
killall -u <your-user-name> cfprefsd
OR
reboot
Items 2. and 3. will cause the cache to be cleared and then your preferences will be reloaded as the cfprefsd restarts automatically.
I hope that helps.

The NSUserDefaults on Mavericks (at least) are cached and it is not recommended to edit the plist files manually. The actual files reside in a container folder (you may know this folder from sandboxing).
But you can use the command line utility defaultsto edit, change or delete preferences. To delete the defaults (= reset defaults for your app) you can run in terminal:
defaults delete com.myapp.* && rm -rf ~/Library/Preferences/com.myapp.*
This is taken from a blog entry that shows in detail explanations on user defaults and mavericks.

Related

How is "Open with" on macOS populated internally?

I know I can associate my application with a certain extension by editing the Info.plist file in my app bundle:
...
<key>CFBundleTypeExtensions</key>
<array>
<string>myext</string>
</array>
While this works, my "Open with" list gets littered with duplicate entries of the different versions of the application I'm developing on that machine. There are even entries for really old versions that I've never opened on that very computer! (It's a new machine being synced with Dropbox so there are older releases in my file system.)
It seems as macOS would scan for app bundles even outside of /Application and adds all applications it finds to "Open with". A workaround is to reset the "Open with" list with this command I found somewhere here on SO I think:
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local -domain user;killall Finder
How is the "Open with" list populated internally? Is macOS really scanning my drive looking for Info.plist files with CFBundleTypeExtensions entries? And is there any way to avoid having my "Open with" list littered with older versions other then deleting (or zipping) them?
NB: I'm not using Xcode but build my application on the command line using the clang compilers and creating Info.plist by a bash script.
How is the "Open with" list populated internally? Is macOS really
scanning my drive looking for Info.plist files with
CFBundleTypeExtensions entries?
I think so, yes. Check the documentation for Launch Services, specifically the section "Application Registration". Specifically, the OS can find your app and register is in the following ways:
A built-in background tool, run whenever the system is booted or a new
user logs in, automatically searches the Applications folders in the
system, network, local, and user domains and registers any new
applications it finds there. (This operation is analogous to
“rebuilding the desktop” in earlier versions of Mac OS.)
The Finder
automatically registers all applications as it becomes aware of them,
such as when they are dragged onto the user’s disk or when the user
navigates to a folder containing them.
When the user attempts to open
a document for which no preferred application can be found in the
Launch Services database, the Finder presents a dialog asking the user
to select an application with which to open the document. It then
registers that application before launching it.
And is there any way to avoid having my "Open with" list littered with older versions other then deleting (or zipping) them?
I'm not sure about that part. Probably not, although it seems like once you reset the Launch Services database using the command in your question, the old versions shouldn't get added back to the Open With list unless you are doing something to trigger getting re-added. Is that the case?

How to clear UserDefaults for Xcode build of Mac app?

I'm trying to make sure my first-run code works properly, and so I'd like to clear the preferences file created by UserDefaults.standard.set calls. Where is it located, or is there at least a way to clear it out (other than writing it into my app)?
Running Product > Clean does not clear out the defaults.
I've looked in DerivedData, ~/Library/Preferences, /Library/Preferences, and haven't found what I'm looking for.
If the app is sandboxed the preferences are located in
~/Library/Containers/[bundle-identifier]/Data/Library/Preferences
If it's not sandboxed the preferences are at the usual location
~/Library/Preferences
You can use defaults command In Terminal
$ defaults delete com.bundle.identifier
Also you can delete any value in defaults by key, if you don't want to delete whole application defaults plist.
$ defaults delete com.bundle.identifier kSomeKey

OS X: NSUserDefaults not saved

I have a sandboxed app for OSX and I saved some data in NSUserDefaults, everything was fine until I deleted the plist file from the ~Library/Preferences/ directory.
I thought the app should recreat it but it did not. When I debug I see that
[[NSUserDefaults standardUserDefaults] synchronize] method returns YES
and data are saved in the class but when I restart the app user defaults is empty.
Even if I copy those plist file from backup to the Preferences directory, the app does not see it.
Of course the plist should be saved in the Containers/my app bundle id/Data/Library/Preferences and when I copy the plist file from backup to that directory, the app can see it, but why that file is not recreated when I deleted it?
Does anybody know why is that?
Check this question - might be related to caching or prefs location when running in the sandbox:
Mac sandbox created but no NSUserDefaults plist
I had this problem, which is caused by deleting the files manually. What you can do instead is to use the defaults terminal command. This way I was able to reset the defaults without breaking things. Replace "bundle-identifier" with your bundle id.
To view the current values:
defaults read bundle-identifier
To remove stored values:
defaults delete bundle-identifier

xcode The document "..." could not be saved

I use xcode 3.2.4 on snow leopard. Today when I tried to save a file on my project I get an error message saying: The document "nameOfFile.m" could not be saved. I tried reinstalling xcode but no luck. The file can be edited with other editors and I see the same behavior on all my projects as well as newly created projects. Any ideas?
Simply by rebooting the computer the issue was fixed.
We were having this problem in a lab environment where user files are mounted via NFS.
The client machines are running OS X 10.6.7 and the file server is running Debian Linux.
After much grief and reading /var/log/syslog on the client machine I discovered it was a subtle file locking / race condition issue with the file system. Evidently, when editing files in a "bundle" (e.g. as in an Xcode project), the OS is using some form of "safe writes" which involves writing transient data atomically to ~/Library/Caches/TemporaryItems/ (which of course is on the NFS mounted system) -- there is a race here that requires proper file locking. We hope we have fixed the problem by changing the nfs_mount options
as described in Mounting NFS volumes in OS X
Not sure why but the temp files ended in a odd state. In "/private/var/folders" I simply removed all the folders and it cleared up the problem
cd /private/var/folders
sudo rm -fR *
Note: never do a "sudo rm" unless you really know what you are doing. It can cause irrecoverable damage
I restarted XCode (by a force-quit, not just closing it) and that fixed it for me.
Make sure you have you mouse focused on the code area and not the file in the file list.
Cleaning the project (Product > Clean), then force quitting Xcode (Command + Option + Escape, select Xcode, click Force Quit) solved the issue for me. I'm not sure if the clean was necessary, but that was what I did. Upon re-opening the project, I let Xcode index the project before doing anything, then did a Build, and all is well.
Force quiting Xcode for me worked. I would recommend the same.
Hey........... even i faced the same problem..... But got the answer......
steps:
reveal in folder the project.
select the file that is locked
select 'GEt Info'
deselect ie uncheck the label 'LOCKED' in the Info.
I just ran into the same problem, then I noticed I ran out of disk space. You can disable the warning that pops up when you run low on disk space (perhaps not a wise thing to do). I did that a few days ago and was puzzled for a moment when this message appeared. They could've just said "Disk full" or something instead of "cannot save". Anyway if anyone ever runs into this just free up some disk space.
You might be able to save in an external editor because its not also building your app which might use up the little remaining space. It might also be why it worked after rebooting (if OS X cleaned up some cached stuff on reboot) so it seems plausible.
Either that or your HDD might have just crashed.
tic....tic....tic.....
In my Case, the File which was saying document could not be saved was basically Shortcut/Allies of the file present at another place.
I don't know why it was not able to save if it was opened by shortcut/allies in xcode but by overwriting(Copy and Paste) the orignal files to that shortcut my problem was solved.
Regards
Umair Bhatti
1.Right click on that file
2.Go to Show in Finder .
3.Click on get info .
4.Goto Sharing & Permission
Everyone,username,Fetching & selection ----You can choose appropriate read write option.
I have face this issue many times. I followed below steps to fixed this.
1. Select file->Show in Finder
2. Copy those file and past different destination.
3. Remove those file from xCode (to selecting show in finder)
4. Then again add those files from other destination to actual location
5. Clean code and run the code.
Another possible reason is that the file you are trying to modify is an alias (i.e. a soft link).
You will have to modify the source file directly in this case.
Thanks #Wayne Cochran,
When I use Xcode to save it, I rebooted the machine several times, and all failed.
So I changed to Visual Studio Code to edit and save. Then it's OK.
Just change the file editor
This can happen when you are working with a network hard drive (or are on a cloud) and not connected to the network (connection lost)

Where is user specified data being stored on MacOS

I install an app .app file to /Applications folder.
Can you please tell me where does the user specified data being stored? How can I do to clean uninstall my application and its user specific data?
Thank you.
This depends on the application, unfortunately. Sometimes it is in ~/Library/ folder, though.
AppTrap should do the trick.
It runs in the background and simply has a preference pane in the System Preferences. Drop the application onto the trash folder and it will ask you whether you want the associated application files to be deleted too.
Just let the user do that. For instance with AppCleaner.
Otherwise, just give a way in your preferences to reset them. No need to delete the plist file.
AppDelete is a free program for uninstalling and cleaning up.
FSEventer is a free program for seeing where programs install themselves.
Most information is stored within /Library/, however from time to time you may find applications which store their data within the contents of the .app package itself, or within a subfolder in /Applications/.
This should give you an idea of where to look.
Where to Put Application Files

Resources