Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 465347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:22:02+00:00 2026-05-12T23:22:02+00:00

I have a situation in which my .dmg file will on my removable storage

  • 0

I have a situation in which my .dmg file will on my removable storage device which contains my application. when i double click on it, it will get mounted on my local machine and inside the mounted volume will be my .app (aplication file). Now I want my application to auto launch once my dmg file is mounted on my local machine. Also now my app needs he info about where the actual dmg file is present like its path on the removable storage device. Is this possible and if so how do i find out the path of the dmg file from which the volume is mounted.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T23:22:02+00:00Added an answer on May 12, 2026 at 11:22 pm
    1. Automatically launching an application is not possible in Mac OS X. There are some safety reasons against it. The only thing that can be automatically launched is a .pkg file and this only through Safari AFAIK.

    2. It is possible to determine the DMG file the application resides on. You have to use IOKit for this. Try playing around with IORegistryExplorer.

    Some code that may help you

    Those are my first attempts on using IOKit, it’s for another purpose but it should help non-the-less.

    // hopefully all needed headers
    #include <sys/stat.h>
    
    #include <IOKit/IOKitLib.h>
    #include <IOKit/IOBSD.h>
    #include <CoreFoundation/CoreFoundation.h>
    
    /* First we want to get the major and minor BSD number
     * of the DMG that our app is residing on.
     *
     * char *path is the path of a file that resides on the disk image.
     * It is like this: /Volumes/Partition Name/SomeFile
     * The simplest method to get such a path is to ask
     * NSBundle for the path of the executable.
     */
    
    // look up device number with stat
    char *path = "path/to/app";
    
    struct stat stats;
    if (stat(path, &stats) != 0) {
        return;
    }
    int bsd_major = major(stats.st_dev);
    int bsd_minor = minor(stats.st_dev);
    
    /* Now that we've got the BSD numbers we have to locate the
     * IOService that has those numbers. IOKit works with
     * CoreFoundation types.
     */
    
    CFTypeRef keys[2] = { CFSTR(kIOBSDMajorKey), CFSTR(kIOBSDMinorKey) };
    CFTypeRef values[2];
    values[0] = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &bsd_major);
    values[1] = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &bsd_minor);
    
    CFDictionaryRef matchingDictionary;
    matchingDictionary = CFDictionaryCreate(kCFAllocatorDefault,
                                            &keys, &values,
                                            sizeof(keys) / sizeof(*keys),
                                            &kCFTypeDictionaryKeyCallBacks,
                                            &kCFTypeDictionaryValueCallBacks);
        
    CFRelease(values[0]);
    CFRelease(values[1]);
    // IOServiceGetMatchingService uses up one reference to the dictionary
    io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault,
                                                       matchingDictionary);
        
    if (!service) {
        return;
    }
    
    /* Now this part is quite different from what I need
     * for my application. I'm not sure how this works
     * because I'm currently not at my Mac and cannot try it.
     * 
     * You need to go up the IOService chain. It looks like this:
      +-o IOHDIXHDDriveOutKernelUserClient
        +-o IODiskImageBlockStorageDeviceOutKernel   <---- You want to get up here
          +-o IOBlockStorageDriver
            +-o Apple UDIF read-only compressed (zlib) Media
              +-o IOMediaBSDClient
              +-o IOApplePartitionScheme
                +-o Apple@1
                | +-o IOMediaBSDClient
                +-o disk image@2               <---- This is the matched IOService!
                  +-o IOMediaBSDClient
     *
     * IODiskImage... has a property "Protocol Characteristics" which is a
     * dictionary that has the key "Virtual Interface Location Path" which is  
     * the path to the disk image. There are probably #defines somewhere in
     * IOKit for those keys.
     *
     * This code is NOT tested. It's out of my head and the documentation.
     * This goes up 4 times in the hierarchy. Hopefully there aren't more
     * than 1 parents.
     */
    
    for (int i = 0; i < 4; i++) {
        io_service_t parent;
        IORegistryEntryGetParentEntry(service, kIOServicePlane, &parent);
        IOObjectRelease(service);
        service = parent;
    }
    
     /* Getting the property from the IOService is the last step:
      */
    
     CFDictionaryRef characteristics;
     characteristics = (CFDictionaryRef)IORegistryEntryCreateCFProperty(service,
                                              CFSTR("Protocol Characteristics"),
                                              kCFAllocatorDefault, 0)
    
     CFStringRef *dmgPath = CFDictionaryGetValue(characteristics,
                                        CFSTR("Virtual Interface Location Path"));
     // clean up
     IOObjectRelease(service);
     CFRetain(dmgPath);
     CFRelease(characteristics);
    
     // Use the path
    
     // later
     CFRelease(dmgPath);
    

    Much of this can be done using the Foundation classes instead of the CoreFoundation classes because of the toll-free bridging support. This makes it a little bit easier and more legible.


    The sample code above is working if the parent IOService of IOBlockStorageDriver is IODiskImageBlockStorageDeviceOutKernel. If the name of the parent IOService is "AppleDiskImageDevice", the IOService chain looks a bit different:

      +-o IOHDIXHDDriveOutKernelUserClient
        +-o AppleDiskImageDevice        <---- You want to get up here
          +-o IOBlockStorageDriver
            +-o Apple Disk Image Media  <---- This is different
              +-o IOMediaBSDClient
              +-o IOApplePartitionScheme
                +-o Apple@1
                | +-o IOMediaBSDClient
                +-o disk image@2        <---- This is the matched IOService!
                  +-o IOMediaBSDClient
    

    You can obtain the image file path URL string like bellow after the for-loop above:

    CFMutableDictionaryRef properties = nil;
    IORegistryEntryCreateCFProperties(service, &properties, kCFAllocatorDefault, kNilOptions);
    if (properties) {
        CFStringRef url = CFDictionaryGetValue(properties, CFSTR("DiskImageURL"));
        CFRelease(properties);
    }
    IOObjectRelease(service);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a situation in which a file exists in both the repo and
I have a situation in which my Java project contains resources from a different
I have a situation in which a CSV is uploaded to my application and
I have the following situation: ParentForm which opens WelcomeForm with ShowDialog . WelcomeForm contains
I have a situation in which there's an HTTP GET parameter with name Date
I have situation in which I read a record from a database. And if
I have a situation in which a managed DLL calls some unmanaged DLL. I
I have a situation in which I need to convert a text data into
I have a situation in which user can single tap a control, which show
I have a situation in which the ideal relationship, I believe, would involve Value

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.