Tried searching on Google but can't seem to find any information.
I need to execute a pkg file which exists within a dmg file via code. Reason is software update. I download an update via my application (which is a dmg) and need to run it. On Windows this is pretty straightforward: run the exe. Having trouble figuring out how to achieve this on a Mac.
As far as frameworks go, I'm using wxWidgets with cocoa (if that helps).
I don't know of a way to do this directly with cocoa APIs, but you can use external commands to do it: use /usr/bin/hdiutil attach /path/to/image.dmg
to mount the disk image, then something like /usr/sbin/installer -package /Volumes/mountedvolume/installer.pkg -target /
to install the package (see man installer
for more information and options). Note that if the package requires admin rights to install, you'll need to run the installer
command as root.
EDIT: to get the full path of the mounted volume, you'll probably have to parse the output of hdiutil
. It'll look something like this, although it'll depend significantly on the format of the disk image:
/dev/disk2 Apple_partition_scheme
/dev/disk2s1 Apple_partition_map
/dev/disk2s2 Apple_HFS /Volumes/mountedvolume