please let me know a working way to auto-launch an application after installing the "pkg" package on macOS.
I’ve tried this: http://macinstallers.blogspot.com/2012/07/scripting-in-installer-packages.html
its doesnt work. Script doesnt work after installation.
package.json:
"name": "test",
"version": "1.0.0",
"description": "test",
"main": "main.js",
build": {
"mac": {
"target": [
{
"target": "pkg",
"arch": [
"x64"
]
}
]
},
"pkg": {
"scripts": "./scripts/postinstall.sh"
}
}
postinstall.sh:
#!/bin/sh
open -a test
exit 0
2
Answers
@Ridham Patel,
Tried to your "Use a postinstall script" method, unfortunately its doesn't work.
Heres my package.json:
Use a launch agent
Create a .plist file in ~/Library/LaunchAgents with the path to your app executable and desired launch parameters.
Set the plist to load on login by running:
launchctl load ~/Library/LaunchAgents/com.yourcompany.appname.plist
This will launch your app automatically when a user logs in.
Use a postinstall script
The postinstall script approach you tried can work, but the script needs to be executable. To fix:
Add postinstall_script.sh to your Electron project
Make sure it has a shebang line #!/bin/sh
Make it executable with chmod +x postinstall_script.sh
Reference it in your package.json:
"scripts": {
"postinstall": "./postinstall_script.sh"
}
Script should contain:
open -a YourApp
Use an install phase script
Add a shell script to run your app to resources/installer.scpt
Reference it in your .pkg definition:
resources/installer.scpt
This will launch your app when the install completes.
So in summary, you can auto-launch an Electron app on install using launch agents, postinstall scripts, or install phase scripts in your .pkg. The launch agent approach runs it on login, while the others launch once on install.