0
votes

I have an app called myapp.app. It is signed and don't prompt any warning when launch.

The goal is to have it installed by an installer silently and launch it. This installer should be triggered in command line.

The solution I imagine is to create an install.app which carries myapp.

Execute "open /Volumes/myapp/install.app".

installer.app copies myapp to ~/Applications and run it.

Is that realistic ?

If yes, creating a cocoa command line application is the way to go?

Would I be able to copy myapp.app to /Applications? (so far all my attempts with swift 3 failed).

[Edit] I was able to copy the Bundle app to ~/Applications/

let sourcePath = Bundle.main.path(forResource: "myapp", ofType: "app")
if (sourcePath == nil) {
    print("myapp.app was not found");
    return;
}

let target = FileManager.default.urls(for: .applicationDirectory, in: .userDomainMask).first
let target_path = target?.appendingPathComponent("myapp.app").path
do {
    try FileManager.default.copyItem(atPath: sourcePath!, toPath: target_path!)
} catch let error {
    print(error.localizedDescription)
}

Now, I am looking to launch it (with swift 3 if possible)

[Edit 2] How it is launched

let run_app = Process()
run_app.launchPath = "/usr/bin/open"
run_app.arguments = [target_path!]
run_app.launch()

Any better way, please let me know.

1
I am not sure if that is possible "silently". I think the user needs to accept that.mcd
Why don't you just copy the application to your desired location and launch it from there using Terminal?oa-
@oa what I need it is to create a program which copies my app to /Applications and launch it. This program could be launched by another program like another installer.arsenik
When should the app be copied and launched? On every user login, once a day, ...?oa-
@oa - just a one time installed and launched for the logged in userarsenik

1 Answers

0
votes

You have two options:

  1. Distribute your application as a package (.pkg) that installs the application.

  2. Prompt the user to move the application to the Applications folder on first launch. There are ready-made frameworks for this: https://github.com/potionfactory/LetsMove

Anything else is poor user experience and your users might question why you are performing actions without asking for their permission.

Also, Gatekeeper will always show a warning if your app was downloaded from the Internet. Even for signed apps.