I am working on simplifying the deployment of a number of things we are doing here at my job. One of the ways I can do this is to include .pkg and .mpkg installers inside my application’s main bundle for deployment. This would allow me to build a package separately and drop it into the /Resources folder of my Xcode project to replace its predecessor.
I have inserted these packages into the Resources of my Xcode project and am trying to find the best way to run them from the main bundle. This examples deals with including the VPN package in my application so that users can attempt a re-install if necessary when they are away from the company network. In my application, I obtain the main bundle and resources location through the following:
on vpnButton_(sender)
set bundlePath to current application's NSBundle's mainBundle's resourcePath() as string
set veePN to (bundlePath as text) & "/VPN.mpkg"
end vpnButton_
Any thoughts on a best practice to run the .mpkg file from there? I have also tried:
set bundlePath to current application's NSBundle's mainBundle's resourcePath() as string
set veePN to (bundlePath as text) & "/VPN.mpkg"
set vpnAlias to veePN as POSIX file
tell application "Installer"
open vpnAlias
end tell
which causes Installer to give an error trying to launch the package. I have also tried Finder instead of Installer, but I get an AppleEvent error -10000 when attempting it this way. My next thought was to try the following:
set bundlePath to current application's NSBundle's mainBundle's resourcePath() as string
set veePN to current application's NSBundle's pathForResource_ofType_("VPN", "mpkg")
but I find that still leaves me wanting to know the best way to launch the application. I would prefer to use ASOC if possible, to call the appropriate Cocoa method, however it is not a requirement. I have read through some other postings which have helped establish what I have tried so far, but did not find anything specific on this issue.
I know this probably isn’t a best practice way of deploying Installer packages, but I want to make the attempt and test my methodology before writing off that it cannot be done. Thanks in advance!
set veePN to current application's NSBundle's pathForResource_ofType_("VPN", "mpkg")
set ws to current application's NSWorkspace's sharedWorkspace()
tell ws to openFile_withApplication_(veePN, "Installer")
Shane, thanks for the reply. Using your code above, I get:
I don’t think ofType likes the mpkg extension, however if I change it to something else like “jpg” I get the same error, so that may not be the issue. For troubleshooting, I inserted a line after ‘set veePN’:
log veePN
but the error above comes up before my log line is able to, telling me that NSBundle is having a hard time setting the variable to the specified entries. It seems like this should work based on how people have successfully used the same syntax to access images in the Resources folder…to test that theory I set it to the following and received the same error as above:
set veePN to current application's NSBundle's pathForResource_ofType_("sync", "icns")
set ws to current application's NSWorkspace's sharedWorkspace()
tell ws to openFile_withApplication_(veePN, "Preview")
Any thoughts? This tells me something about how I am calling NSBundle pathForResource_ofType_ might be incorrect.
It is worth noting that the first go-round of package importing I must have done something incorrectly, as some of the errors I was getting made it seem like it could not find the package, when I was calling the direct POSIX path from plain Applescript. After I built a distribution of the project to see the results there, I did a Show Package Contents and found that the packages were in fact, missing.
Final code is below and sits inside a try statement that calls NSAlert on error, just in case. The NSAlert tells the user where to go to get the most up to date package if this installer package is not working:
set veePN to current application's NSBundle's mainBundle()'s pathForResource_ofType_("VPN", "mpkg")
set ws to current application's NSWorkspace's sharedWorkspace()
tell ws to openFile_withApplication_(veePN, "Installer")