1

How can I programmatically determine which (if any) mounted volumes are a DVD?

I currently look for a directory with permissions 555 but I would prefer something a bit less hacky. Thanks!!

$ ls -l /Volumes/
total 12
dr-xr-xr-x  4 mh    gfx    136 Aug  3  2001 DQRMX2102
lrwxr-xr-x  1 root  admin    1 Apr  6 15:09 Macintosh HD -> /
drwxrwxr-x  9 mh    gfx    374 Feb  3 12:55 data

2 Answers 2

5

What programming language/toolkit are you using?

If you're using Cocoa in Objective-C, you can NSWorkspace:

NSArray *volumes = [[NSWorkspace sharedWorkspace] mountedRemovableMedia];

If you want to find out from the command line or a script or something, diskutil should come in handy.

$ diskutil info -plist /Volumes/Foobar
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
...snip...
    <key>OpticalMediaType</key>
    <string>CD-ROM</string>
...snip...
</dict>
</plist>
1
  • it might also say DVD-ROM instead
    – rogerdpack
    Apr 21, 2011 at 6:40
3

For Cocoa, you can use NSWorkspace mountedRemovableMedia: to get a list of volumes and the use NSWorkspace getFileSystemInfo:... to get more information about each mounted volume.

- (BOOL)getFileSystemInfoForPath:(NSString *)fullPath 
                     isRemovable:(BOOL *)removableFlag 
                      isWritable:(BOOL *)writableFlag 
                   isUnmountable:(BOOL *)unmountableFlag 
                     description:(NSString **)description 
                            type:(NSString **)fileSystemType

If you want to make system calls, you can use statfs at the same information.

int statfs(const char *path, struct statfs *buf);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.