Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting App / NSUserDefaults data on macOS

I am from iOS dev background and writing my first MacOS app in Swift.

On iOS, if I want to delete the app's NSUserdefaults, I would tap/hold the app icon on my device and delete it.

On MacOS, however, I do not see my app icon in applications folder. What am I missing?

Note: My app only appears in status bar ( I have Application is agent (..) = YES in my info.plist)

like image 641
Kashif Avatar asked Feb 02 '17 20:02

Kashif


2 Answers

If you are trying to delete your preferences to reset them then you need to use the defaults command. MacOS uses a cache system for preferences and deleting the preferences file itself has not been recommended by Apple for a long time. In Terminal enter:

defaults delete your.app.bundle.id

This will remove the file and any cached settings.

If you wish to delete the whole app then that depends on whether it is sandboxed or not. First delete the preferences as above.

If it is sandboxed you delete the directory ~/Library/Containers/your.app.bundle.id.

If it is not sandboxed you must remove individually anything you've added to paths such as ~/Library/Application Support etc.

In both cases you need to delete the name.app file itself.

HTH

like image 94
CRD Avatar answered Sep 17 '22 19:09

CRD


As a side note to anyone like me who ends up at this question, if you're developing a macOS screensaver and storing configuration settings in UserDefaults, you need to do

defaults delete com.apple.ScreenSaver.Engine.legacyScreenSaver

to delete your screensaver settings. This will likely wipe out all settings for any custom screensavers installed but I wasn't able to find another way.

like image 29
Brad Root Avatar answered Sep 19 '22 19:09

Brad Root