Copy App To Applications Folder macOS

Hi,

I’m trying to build my own install app for my products for macOS, and I’m having difficulty copying the application to the Applications Folder on the Mac.

I have this code:

Dim f4 As FolderItem f4=GetFolderItem("MyApp") If Not f4.Exists Then MsgBox "File Does Not Exist" Else f4.CopyFileTo(SpecialFolder.Applications) End If

I get the MsgBox that the "File Does Not Exist and nothing is copied. MyApp is stored in the same folder as my project so I don’t know why it can’t find it. Can anyone see what I’m doing wrong.

The name of your app is likely “MyApp.app”

…and a folder as .app denotes a bundle on macOS.

Thank you Roger and Greg. That did the trick. Thanks so much for taking the time to help me. I appreciate it.

James, before you get too far into this project, I must warn you that you are likely to encounter several “security” problems.

  1. A lot of recent set-ups have ‘secure’ /Applications folders, which means that applications cannot write to that directory.
  2. Apple’s “App Translocation” security mechanism may cause problems here, it appears the guaranteed way to NOT incur translocation rath is to ship the application on a signed DMG and have the user drag it to the /Applications folder.
  3. If you’re thinking to ship on the Mac App Store, you must use an Apple installer, not your own.

I’m not saying this to poo-poo your idea, just that modern macOS security will cause you some headaches, and these what I know of today.

You used to be able to use Apple Script to control the “Finder”, so you could get the Finder to move the application to the /Applications folder, however I’ve gotten a handful or reports recently that this no longer works (as I use it for the App Wrapper installer).

So there are two Apple recommend means which don’t cause security problems (yet).

  1. Signed DMG and have the user drag the app into the /Applications folder folder, you’d be surprised how many people don’t understand this.
  2. Use an Apple installer, which some users don’t trust as there’s no easy way for the user to verify what’s being installed and where. In fact Apple’s installer by default doesn’t communicate to the user at the end of the installation process, where the application was installed to. Something that’s very counter-intuative.

Do your own installer really if you have to. I needed an installer because my main app needs a helper app that has to be running after installation.

  • Don’t use CopyFileTo. It will mess with the permissions. Use ditto instead.
  • Don’t use an IDE copy step to copy your main app into the installer. Also use ditto.
  • When you don’t have permissions to delete or copy then you will get an error -5000. Then you need to start with AuthorizationMBS.
  • The drawback of AuthorizationMBS is that you need fixed shell scripts which is a bit of a pain.

[quote=400411:@Beatrix Willius]

  • The drawback of AuthorizationMBS is that you need fixed shell scripts which is a bit of a pain.[/quote]
    You don’t need to use shell scripts. You could use a separate Xojo helper app to do this.

Hi Sam, Beatrix, and Kevin,

My apps use SQLite databases to store data, and I used to be able to install the entire application plus databases all in the Application folder. Then Apple made it harder to write data to the Applications folder under Lion or Mountain Lion. (I can’t remember which.) When I tried to save data back to the database from the app, it would not save.

So I had to install the databases and other support folders in the Documents Folder. I did not use the Library/Application Data folder, because my customers needed to have easy access to those database files and the Documents folder was easy to find.

I used an installation app call File Storm which has always worked great for me for the most part. You could easily install different elements of your application pretty much anywhere, and you could determine if existing files would be overwritten, left alone, or you ask the user what to do with them.

http://www.mindvision.com/filestorm.asp

It looks like File Storm was 32 bit and when I contacted the company they said they were not upgrading the application to 64-bit, so since Apple is phasing out 32-bit apps, I decided I would have to write my own 64-bit installer. So that is what I’m trying to do.

When using File Storm I would have no problems with most installs, but lately, I get maybe 1 out of 100 or so customers who report that the “Application Finished With Errors.” Basically, it could not copy my app folder to the Applications folder. So this is what you must be talking about as the “Secure Applications Folder.”

I tested this code and it seems to work fine thanks to those who helped me earlier.

[code]Dim f as FolderItem
f=GetFolderItem(“MyApp.app”)

If Not f.Exists Then
MsgBox “File Does Not Exist”
Else
f.CopyFileTo(SpecialFolder.Applications)
End If[/code]

How can you tell whether a customer’s computer has a ‘secure’ /Applications Folder? If it can be turned off for the install, then I could tell the customer to turn it off. I don’t know how FileStorm copied the app to the Applications Folder, and because of the ‘secure’ Application Folder some of my installs would report ending with errors and not copy the application.

If the install only fails 1 out of 100 times, I could also include one of those Drag to the Applications folder DMGs as a backup method.

As far as Ditto, I don’t know anything about it and would not know how to implement it.

@James Redway: you need at least to check the last error when copying. When you get -5000 as error then you can’t write to the folder.

Add another user to your computer without admin rights for testing.

@Kevin Gale: shudder. I’m now up to 6 apps: main app, installer, helper app. Helper app for bug in Evernote. Another helper app for the server version. What did I forget?

James, Packages is a free installer and 64bit too. I haven’t use it but I found information about it here.

I logged on as a guest and it did NOT install into the Applications folder, but I would not expect that. Because of the nature of my apps, I think all my customers would have administrative rights, and if they don’t, I’m not sure if I wanted them to install the software on that computer.

[quote=400461:@Alberto De Poo]James, Packages is a free installer and 64bit too. I haven’t use it but I found information about it here .

[/quote]

I tried Packages and I thought it was pretty good, but I could not figure out how to write files to the Documents folder. The biggest problem I had with it was that it would overwrite existing database files, and there was no option to ask the user if they would like to preserve or overwrite the files.

I contacted the developer and he wanted to know why that would be important. I told him that my customers have a custom database file and if they updated the application, there should be a way to preserve existing files, or overwrite them to start over. I have not heard back from him.

If he could add the features I need, I would certainly use it. It’s a free app so I’m sure the incentive to add new features is not really a priority. I would gladly pay for the app if it did the things I needed.

Include a database in the app’s resource fork, then when the app launches, have it copy the database to Documents if it doesn’t already exist there. That will preserve any existing DB. You could also add an option to check the timestamps on both databases and then ask the user if they want to replace the existing DB with a newer one.

I don’t really know what resource forks are. In looking at the Xojo documentation it appears that they are depreciated.

I was sort of looking to see if there was a way to store the sqlite database files and some text files right in the build. I have two database files and about 5 Readme text files. Is there a way to embed them directly into the build? That way when the DMG folder is uncompressed the install app will have everything built right in. You can do that with iOS Builds. Is it possible with macOS?

Sorry, I meant in the app’s Resource Folder.

Thanks John. The Resource folder was the answer to keeping everything together and packed neatly inside the Install app. The Install program can now install the database files in the correct spot and check to see if the user wants to overwrite them. Thanks for your help. I appreciate it.