How to delete an application in sandboxed App? - macos

I am trying to delete an application in the /Applications folder on macOS High Sierra (I don't hink the exact OS really matters).
But I simply can not figure out, how to do so from a sandboxed app. In the Mac App Store there are a couple (in fact a lot) of apps that can do that.
When an app is selected, a prompt is shown where I can type in my password.
First I tried creating a helper utility and then calling SMJobBless. But after failing I noticed that this is not possible in a sandboxed app (kinda makes sense because you could completely bypass the sandbox?).
Then I tried to write an AppleScript. This really works fine, the prompt is shown and the file is either deleted or moved to the trash.
I had to add an entitlement:
com.apple.security.temporary-exception.apple-events
I have added co.apple.finder as a child node and like I said everything works fine. Unfortunately, this entitlement is not allowed in the Mac App Store (again, this makes sense).
Now my question is...how can I move a file to the trash (I do not need to delete it myself, it would be okay if the user had to empty the trash manually).
How do all those other apps do it?

Only way I can think of would be to open an NSOpenPanel, and get the user to select the application you want to delete. Not too many MAS-approved ways to poke through the sandbox beyond that.

Related

Verifying "Xcode" on every macOS boot

every time I start or restart my MacBook, macOS verifies Xcode.
This is not a picture from me I took it from another post but its basically the same just with "Xcode" (the app) instead of the image file.
It takes a while and for the time macOS is verifying Xcode the fan of the MacBook goes like to 100%. While its verifying I can't really use other applications because they freeze and will unfreeze when the verification is finished.
I tried to remove the quarantine xattr from the Xcode.app and recursively from all package components but there never was one set xattr: /Applications/Xcode.app/: No such xattr
I also tried to to reinstall Xcode. When booting into safe mode the same verification window appears.
This happened after I updated my mac to macOS Catalina. If you have any idea what I can try next, let me know.
Ok so apparently in my case there was something messed up with my system. I couldn't find any solution and besides the Xcode problem Reminders always wanted to access a keychain of mine. Not the login, the system or iCloud Keychain but a keychain I created myself just to store and organise some password. And when I clicked on "Deny" Reminders would ask again so I only could close this window and be able to do other things when I allow access.
Anyway after I completely reinstalled macOS (first erase the whole Macintosh HD and then reinstall Catalina) everything works fine.
So if any of you doesn't have that much of data on their Mac just a few files to back up I'd definitely try a reinstall. Took my 3-4 hours and now it works again.

Uninstall macOS app

I am testing my macOS app, and I need to uninstall it to check some special features. For iOS apps this is very simple, I simple remove the app from the simulator and then I reinstall it. How can I do the same thing for macOS?
I've already tried to delete the app from /Users/myuser/Library/Developer/Xcode/DerivedData/Build/Products/Debug/myapp.app
But that doesn't work. If I run my project again, all previous settings and saves are kept.
How can I completely remove an app made in Xcode for macOS development?
The topic: Delete app from OSX simulator in Xcode didn't help me.
This command will delete whatever's in the UserDefaults database for your app:
defaults delete com.mywebsite.myapp
Replace com.mywebsite.myapp with the bundle ID of your application.
If you have items other than just UserDefaults settings, they'll appear in the home/Library/Containers folder in a folder named after your app bundle (assuming your app is sandboxed; otherwise check home/Library/Application Support). You'll find the plist file for your UserDefaults in here as well, although deleting that using the Finder isn't reliable, since the system sometimes caches the plists in memory, so the defaults command is still the best way to clear that.
There are many apps that allow you to thoroughly uninstall apps, for example AppCleaner. However I'd try to use the clean build folder option within Xcode first.

After changing Document Parameters, NSCocoaErrorDomain 256 opening *new* docs

For the next version of a NSDocument-based app, I am revising the document parameters, that is, the values in Info.plist > CFBundleDocumentTypes and UTExportedTypeDeclarations. Specifically, I am changing from a flat NSPersistentDocument to a document package (with the help of BSManagedDocument).
The revised app can create new documents, but they appear in Finder with a generic icon, and when I close such a new document and try to re-open it, -[NSDocumentController openDocumentWithContentsOfURL:display:completionHandler:]fails, creating an error in NSCocoaErrorDomain with code 256, description “newDoc.myExtension” could not be handled because MyApp cannot open files of this type, and failure reason MyApp cannot open files of this type.
I understand that there are several significant parameters CFBundleDocumentTypes and UTExportedTypeDeclarations, and these must all be correct or you get this error. In this case, they are correct. I've confirmed this by comparing the Info.plist in my built product with the Info.plist of a different but similar app that works.
I've also tried calling LSRegisterURL() with inUpdate = true from main(), but that did not help.
What might be wrong? I'm running in macOS 10.12.6, building with macOS 10.13 SDK and Xcode 9.
Apparently the problem is in updating the Launch Services database. I copied the new application, with the revised Info.plist, into /Applications, replacing an old version, then launched this copy once. After these two steps, document icons are now correct when I reopened a Finder window, and upon relaunching my new app, it can now reopen its own new documents without error.
UPDATE: Today (macOS 10.13 Beta 8) I had the same problem, but installing the corrected app into /Applications did not work. However, this time, rebuilding the Launch Services database by running the following command in Terminal, and then relaunching my app, did work:
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain u -domain s -domain l -v
A side effect of the above is that some apps will have generic icons in the dock and cmd-tab application switcher until relaunched.
I think that either Launch Services much prefers apps in /Applications over apps in Xcode's DerivedData folder, even if the latter is the only one currently running, or running apps from Xcode's DerivedData do not register at all, or both.
It seems from the documentation that calling LSRegisterURL() should have had the same effect, but apparently not.

OSX Removing app data from Xcode

New to OS X development and have tried removing ~/Library/Developer/Xcode/DerivedData from my system, Product>Clean but still wouldn't wipe the data. I know its much simpler in iOS simulator. Any advise on removing OS X app data completely so that it runs like as if its the first time?
Unlike iOS apps, macOS apps don't delete all of their data when uninstalled.
Assuming the data you are referring to is stored in the UserDefaults, this is the solution I found to test the app first launch.
Quit Xcode
Remove the DerivedData folder
Delete the UserDefaults plist file. Depending on your app's configuration it will be in one of these locations (more info in this answer):
Sandboxed apps:
~/Library/Containers/com.example.myapp/Data/Library/Preferences/com.example.myapp.plist
~/Library/Containers/com.example.myapp/Data/Library/SyncedPreferences/com.example.myapp.plist
Non sandboxed apps:
~/Libraryf/Preferences/com.example.myapp.plist
~/Library/SyncedPreferences/com.example.myapp.plist
Relaunch the app from Xcode
If the only thing you need to test is a flow based on a "first launch flag" (a Bool in the UserDefaults that is set to true after first launch), you can reset that one along with this command:
defaults write com.example.myapp "settingName" "0"
You'll still have to quit Xcode, delete the DerivedData, and re-open Xcode for the change to take place.
Note that sometimes this doesn't work on the first try. I'm not sure why but I'm guessing Xcode does some state tracking inside that gets in the way. In my experiments, I had to restart Xcode a few times before getting it to read the updated defaults.
Oh just open up the Simulator and click (and hold) on the app icon. Then it'll shake and you click the 'x' in the corner to delete the app and its data.

prohibitory sign on application icon (broken folder) on Snow Leopard

I have prepared a disk image with my application,which i want to install in Applications folder. When i copy the application from the disk image to the applications folder, i see that first it gets generic application icon (sometimes my application icon with a prohibitory sign (or broken folder) ). It becomes executable application after a couple of seconds (some 10 seconds)
I wonder if somebody has experienced something similar?
EDIT: On my customer computer with Snow Leopard the application stayed with a prohibitory sign (broken folder) . How do i fix it? It worked on Leopard
Yes this happens to me too. That is (supposed to be) the appearance of an app that cannot run on your particular platform, e.g. an Intel program on a PPC machine. Not sure why it does it to legit apps, but it seems to go away after a while (perhaps after it is run once?)
As I suspected it was a permissions problem. When build an installer with a Packager all items have to have a root as owner and wheel as group for permissions.
Why it stays that way is another question (perhaps related to caching?), but the reason for a copied application temporarily displaying as broken is simple: it is broken. That is, while it is being copied, it is incomplete, and therefore "broken". When the copy is complete, the application icon should update to indicate a good application.
If it doesn't this might be because the copy failed for some reason, or because the intermediate result is cached. In that case try refreshing by simple closing the Finder window and reopening it.

Resources