Open app after installation from pkg file in Mac
Asked Answered
U

5

5

I've created a SampleApp.app file from XCode 7.1 and converted it to pkg file and signed it using the product build command and it worked fine. But now the problem is, when I install the pkg the app does not start automatically after installation. Do I need to include any other arguments in my command to make this work? Below is the command that I use to create and sign the pkg.

productbuild --component SampleApp.app /Applications SampleApp.pkg

productsign --sign "Developer ID Installer: xxxxx" SampleApp.pkg SampleApp_signed.pkg

EDIT

I've also tried to add a postinstall script but that didnt seem to work, I'm not sure if its the problem with my script or command

pkgbuild --root SampleApp.app --identifier com.companyname.SampleApp --scripts startup.sh --install-location /Applications/SampleApp.app SampleApp.pkg

productsign --sign "Developer ID Installer: xxxxx" SampleApp.pkg SampleApp_signed.pkg

My startup.sh file

#!/bin/bash

open -a /Applications/SampleApp.app

exit 0
Unessential answered 25/2, 2016 at 5:23 Comment(12)
what did you finally do to get this to work. I am doing the very same as your edited post... even chmod executable the startup.sh file... but nothing ever happens for me. my commands and script are identical to yours except the app name and key name... the script just doesn't seem to runSpadework
never mind I got it.Spadework
@JasonReeves how you able to make it run? I chmod the .sh file and then attached in pkgbuild command but it never fires after installation done!Joinville
@SantanuKarar first, the file must be named postinstall.sh second, the --scripts path had to be the fully qualified path to the scrips folder i.e. /Projects/myproject/bin/scripts and make sure it points to the folder... not the file. then when you run pkgbuild, you will see in the console "adding postinstall script" (or something like that) and you will know you have it set up correctly! Took me a while to figure this one out!! Hope this helps!Spadework
This not worked for me strangely. My commands were: $ pkgbuild --root Helper.app --scripts "/Users/santanu/Documents/Adobe Flash Builder 4.7/SVNBranch/Helper/build/Scripts" --install-location /Applications/Helper.app newBoot.pkg. Following were my output - pkgbuild: Inferring bundle components from contents of Helper.app. pkgbuild: Adding component at Contents/Frameworks/Adobe AIR.framework. pkgbuild: Wrote package to newBoot.pkg - but these never starts postinstall script that I attached.Joinville
I also did chmod stuff to the postinstall file before pkgbuild, I also tried to expanding the pkg file pkgutil --expand newBoot.pkg expandedFolder and I confirm I had postinstall.sh file inside it's Scripts folder.Joinville
To keep a note, this finally worked for me. But following steps specifically worked for me. 1. Put a non-extension executable inside a folder and make sure it's must named preinstall or postinstall. 2. Apply chmod 755 and chmod a+x to the file, 3. No need to mention absolute path in pkgBuild command but point the folder containing postinstall script for --scripts field. Finally I received "Adding top-level postinstall script" result in my packaging.Joinville
@Gamerlegend How can I create "My startup.sh file". Please help me.Attica
@Giresh, if you are on mac, open terminal and choose any editor for eg:Enter sudo vi startup.sh and press "i" and copy paste required content then press esc :wq, now make it executable by entering sudo chmod a+x startup.sh That's it!!!Unessential
Thanks @GamerlegendAttica
@Gamerlegend in my cash the app not opening after installing from .pkg file. Can you please give me details step by step process.Attica
First u need to make your .sh file executable as I mentioned in my above comments then use the command given in the question to add postinstall script to pkg file. Just make sure your app opens by typing command: sh startup.sh in terminal. If it opens then you should be good to go.Unessential
S
0

Usually you would create a postinstall script, and include it with the --scripts option.

--scripts scripts-path

The contents of scripts-path is added to the product archive for use by system.run() commands in the distribution. This is valid only for product archives targeted to the OS X Installer application.

So a (very) basic example of postinstall could launch an app by:

#!/bin/sh

open /path/to/your/app
exit 0
Subtlety answered 25/2, 2016 at 7:15 Comment(4)
I've tried this but my app still doesn't open after installation, I dont get any errors while creating and signing the pkg, is there any problem with my script file? I'm on EI CapitanUnessential
I tried --scripts ./startup instead of startup.sh but says the file “startup” couldn’t be opened. And when I build with startup.sh it gets created but doesnt work. Any advice?Unessential
It was my mistake, I had to make the startup.sh file executable using chmod a+x startup commandUnessential
@Gamerlegend: The script might need root:wheel ownership set (if not already or via pkgbuild), although might not matter if you're just opening the app.Smut
D
3

As Santanu Karar mentioned in a comment:

  1. Put a non-extension executable inside a folder and make sure it's must named preinstall or postinstall.

Note: Not postinstall.sh but postinstall!

  1. Apply chmod 755 and chmod a+x to the files preinstall and/or postinstall.
  2. No need to mention the script's full path in the pkgBuild command. Point the folder containing postinstall script for the --scripts parameter.

As in --scripts "./Scripts/" and not --scripts "./Scripts/postinstall"

Lastly, it safer to use open "$2/App Name.app/" in the script, as $2 is the install location, and it's passed to the postinstall script.

Duck answered 13/2, 2018 at 13:44 Comment(1)
In my case, $2 is actually the install location *including the App Name.app directory name.Peculium
P
3

For many apps, you don't want to fire them up as sudo/root, so, you'll want to launch it as an ordinary user (e.g the one installing)

su "$USER" -c "open path/to/MyApp.app"

Note, there are many things in pkgbuild that are either undocumented, archived, or hard to find docs for online, such as $2, which is the path to the application you're installing.

This means you can also do this...

su "$USER" -c "open $2"

There are other variables as well, such as INSTALLER_TEMP, which I use in one of my scripts to know if a command line utility my app ships with is being run during install or during normal operation. The variable isn't very useful otherwise.

Bitrot warning... At time of writing this, Google has 4 search results for INSTALLER_TEMP pkgbuild and GitHub turns up one single result for some savenotes so I feel it important to ask (and answer) and ultimately archive here so that there are secondary copies of these techniques.

Peculium answered 14/10, 2019 at 6:37 Comment(0)
T
2

I had to use sudo in the postinstall script to get it to work:

#!/bin/sh

sudo open -a 'appName'

exit 0
Tinder answered 17/3, 2017 at 6:47 Comment(0)
S
0

Usually you would create a postinstall script, and include it with the --scripts option.

--scripts scripts-path

The contents of scripts-path is added to the product archive for use by system.run() commands in the distribution. This is valid only for product archives targeted to the OS X Installer application.

So a (very) basic example of postinstall could launch an app by:

#!/bin/sh

open /path/to/your/app
exit 0
Subtlety answered 25/2, 2016 at 7:15 Comment(4)
I've tried this but my app still doesn't open after installation, I dont get any errors while creating and signing the pkg, is there any problem with my script file? I'm on EI CapitanUnessential
I tried --scripts ./startup instead of startup.sh but says the file “startup” couldn’t be opened. And when I build with startup.sh it gets created but doesnt work. Any advice?Unessential
It was my mistake, I had to make the startup.sh file executable using chmod a+x startup commandUnessential
@Gamerlegend: The script might need root:wheel ownership set (if not already or via pkgbuild), although might not matter if you're just opening the app.Smut
D
0

ok because OSX is so dumb and stupid, don't use application path instead use app name or bundle id because it seems OSX needs time to figure out that your application is actually an application:

you can open using bundle id:

#!/usr/bin/env bash

open -b 'com.myapp.mac'

exit 0

or open using app name:

#!/usr/bin/env bash

open -a 'MyApp'

exit 0
Dismay answered 29/7, 2016 at 11:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.