Does a system call or library exist that would allow my C++ code to use hdiutil on Mac OS X. My code needs to mount an available .dmg file and then manipulate what's inside.
+2
A:
If you can use Objective-C++, you can use NSTask to run command line tools:
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath: @"/usr/bin/hdiutil"];
[task setArguments:
[NSArray arrayWithObjects: @"attach", @"/path/to/dmg/file", nil]];
[task launch];
[task waitUntilExit];
if (0 != [task terminationStatus])
NSLog(@"Mount failed.");
[task release];
If you need to use "plain" C++, you can use system():
if (0 != system("/usr/bin/hdiutil attach /path/to/dmg/file"))
puts("Mount failed.");
or fork()/exec().
You'll need to double-check whether hdiutil
actually returns 0 for success or not.
Dewayne Christensen
2010-01-05 19:17:43
+3
A:
hdiutil
uses DiskImages.framework; unfortunately, the framework is private (undocumented, no headers), but if you're feeling adventurous, you can try to use it anyway.
ephemient
2010-01-05 20:10:31
A:
hdiutil
has a -plist
argument that causes it to format its output as a standard OS X plist. See this for info on processing the output from hdiutil; because you'll likely have to examine the output a bit to find what you need, it may be easy to do this initially with something like python
. Then see here for some suggestions on parsing plists in C++.
Ned Deily
2010-01-05 22:18:49