cannot copy application into /Applications folder

Hi


I am using from a C++ application the following bash command


cp -r MyApp.app /Applications


but no file is copied into /Application folder. This happens on macOS Catalina, but not on older OSs


thanks

Bogdan

Replies

On Catalina, you will have to use the Finder to copy an app into Applications or use the data volume path.

On Catalina, you will have to use the Finder to copy an app into Applications or use the data volume path.

What makes you say that? I’m able to copy things to

/Applications/
from Terminal just fine:
$ cp -R ManOpen.app /Applications 
$ ls -lhd /Applications

Also, the data volume path for

/Applications/
is
/Applications/
. It’s the system applications that were relocated, to
/System/Applications/
:
$ ls -lh /System/Applications 
total 0
drwxr-xr-x   3 root  wheel    96B Sep 13 23:06 App Store.app
…

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

First up, I recommend that you not copy applications by shelling out to

cp
. Rather, you should use an API for this. The best API for this is
NSFileManager
, but if you want to avoid Objective-C / Swift then
copyfile
is just fine. See its man page for details.

IMPORTANT If you continue using

cp
, use the
-R
flag. The
-r
flag will break the app if it contains any symlinks (I relearnt that lesson the hard way recently)-:

Once you switch to an API, things will either work or you’ll get some sort of error. If it’s the latter, please post info about that error.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
  • In my case, a shell script is unavoidable (post-install script in an Mac Installer .pkg). However, copying the .app bundle completely (using cp -R) seems to work fine --- only if USER then double-clicks the app to open it.

    If however, another app will use NSWorkspace API to try and launch it, I get an error dialog saying the app is corrupt - and the NSError says it couldn't find a binary to run!!!

    `                NSWorkspace *ws = [NSWorkspace sharedWorkspace];                 NSWorkspaceOpenConfiguration *conf = [NSWorkspaceOpenConfiguration configuration];                 conf.addsToRecentItems = NO;                  conf.activates = NO;                 conf.hides = NO;                  conf.appleEvent = appleEvent;

                    NSURL *appURL = [ws URLForApplicationWithBundleIdentifier:appBundleID];                 [ws openApplicationAtURL:appURL configuration:conf completionHandler:^(NSRunningApplication * _Nullable app, NSError * _Nullable error) {                     if (error!= nil)                         NSLog(@"Failed to launch app UI %@, error:%@", appBundleID, error);                     else                         NSLog(@"Launched app %@ in the background.", appBundleID);                 }]; ` Maybe an AppleScript will "install" it better? the app isn't installed in /Applications, but rather in a private place, and is a menu-bar "status item" app

  • I'm sorry I can't read your post. I recommend that you start a new thread (using the Files and Storage tag) and we can pick things up from there.

Add a Comment

(I am working with Bogdan)


Thanks eskimo! Your suggestion to use the NSFileManager API worked. I used the copyItemAtPath method. 🙂

eskimo wrote:


What makes you say that?

I assumed that the OP was a beginner programmer learning C++ and trying install an app into the Applications folder. I thought an end-user approach using the Finder would be more helpful along with a comment about the data volume that might encourage them to learn more about it.


I'm not entirely sure what jrumo's co-worker relationship to the OP is or why an Objective-C API would work in a C++ program. Perhaps I don't know all the details.


I always thought that /Applications in Catalina was a firmlink to /System/Volumes/Data/Applications on the data volume. I have seen some really interesting re-arragements of system files in Catalina. And I have seen people doing some truly bizzare things with system files. I realize that firmlinks are perfectly useable, but I really would not recommend people engage in command-line operations on this particular path. Either they don't know what they are doing and need to learn the proper way to install apps or they need to fully understand what has changed in Catalina before they start applying hacks.

Your suggestion to use the NSFileManager API worked.

Excellent news.

Oh, and btw, john daniel’s comment about hard coding paths is important. I’ve just posted some advice on how to find these directories on another thread.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks John! That's helpful to know.


Btw, the application is written in the Qt framework, and already had some Objective-C code, so it was easy to switch over to the NSFileManager API. 🙂

I guess I was wrong about the beginner assumption then. You are going to have to be really careful using something like Qt. Those open source frameworks are often years behind developments on macOS. If you have a bunch of C++ code that you can't do without, there are better ways to integrate it into a modern app, especially on macOS. iOS is more of a challenge. It is best to stick to Apple's frameworks for Apple's UI.