Search code examples
macosinstallationdmg

Get filename of executing dmg package


Is there a way to get the name of the dmg package an app is started/installed from?


Solution

  • Your question is quite unclear, since I can not figure out what name you want to get. But in any way, the answer will be the same: No, there is no direct way.

    Name of the .dmg-file

    The name of the .dmg-file is impossible to find out, since the file is mounted as a volume. Usually the mount-point (/Volumes/xxxx) has the name of the .dmg-file, but if the mount-point already exists, the name is extended with a number. It is possible, that the .dmg-file had a number in the end; so you can not simply drop the number in the end, cause you do not know if it was extended due to the fact, that the mount-point was already in use, or the fact, that the name had a trailing number.

    Name of the installer package

    Where do you need to find out the name of the installer package? In a Pre- or Postflight-Script? There is not really a simple way to find out the name of the installer-package, but there might be some workarounds to reach the target you want.

    UPDATE / Solution:

    I found a way, to find out the name of a mounted dmg-file: Run the following command on terminal (can be also done by a script, so that the result can be used within a program):

    hdiutil info
    

    The result will look something like this:

    ================================================
    image-path      : /Users/username/Downloads/yourDMGFile-v2.0b10.dmg
    image-alias     : /Users/username/Downloads/yourDMGFile-v2.0b10.dmg
    shadow-path     : <none>
    icon-path       : /System/Library/PrivateFrameworks/DiskImages.framework/Resources/CDiskImage.icns
    image-type      : UDIF, read only, compressed (zlib)
    system-image    : false
    blockcount      : 80040
    blocksize       : 512
    writeable       : false
    autodiskmount   : TRUE
    removable       : TRUE
    image-encrypted : false
    mounting user   : username
    mounting mode   : <unknown>
    process ID      : 17177
    /dev/disk5  GUID_partition_scheme   
    /dev/disk5s1    48664310-0200-11FC-ACX1-00360534ACDC    /Volumes/yourDMGFile v2.0b10
    

    Here the name of the dmg-file is printed out, as well as the name of the mount-point and further informations about the .dmg-file as well.