Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
Applescript.

Code:
tell application "System Events"
	set freeSpace to free space of disk "Macintosh HD" as real
	return freeSpace
end tell

Like chown33 said, which language?

Regards Mark
 
Sorry I thought this was an Xcode forum. Objective C.

The name of this forum is "Mac Programming". The Mac supports many different programming languages. So does Xcode.


There is a C framework named "DiskArbitration". See here:
https://developer.apple.com/library...s.html#//apple_ref/doc/uid/TP40009310-CH3-SW1

You can get a DADiskRef, then get a CFDictionaryRef from the DADiskCopyDescription function. From that CFDictionaryRef (which is toll-free bridged to NSDictionary) you can then get any of the keys describing the disk. One such key is kDADiskDescriptionMediaSizeKey.

For more info, read the header:
You can find a complete list of properties in the DADisk.h header in the Disk Arbitration Framework, along with a description of the expected data types for the values of each key.
Quoted from the subsection "Obtaining a Description Dictionary" of the Manipulating Disks reference linked above.

Also look at the links to the framework function references. Each function has a link to a relevant Sample Code project. Look there, too.
 
Another way is to use the NSFileManager class.

Something like:

Code:
unsigned long long fs_size;
NSDictionary *fs_attrib = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[pathURL path] error:nil];
fs_size = [[fs_attrib valueForKey:NSFileSystemSize] longLongValue];

Fill in for the appropriate path. And you should probably actually check for an error. ;)
 
Another way is to use the NSFileManager class.

Something like:

Code:
unsigned long long fs_size;
NSDictionary *fs_attrib = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[pathURL path] error:nil];
fs_size = [[fs_attrib valueForKey:NSFileSystemSize] longLongValue];

The attributesOfFileSystemForPath:error: method returns the attributes of a file-system, not a hard drive. For example, it won't account for other partitions, such as the recovery or EFI partitions. Also, if the disk has multiple user-defined partitions, it won't account for any of those.

To illustrate the difference, copy & paste this command into a Terminal window:
Code:
diskutil list
The item labeled "0:" will be the disk as a whole, i.e. the "hard drive". Each partition will also appear, i.e. the "file-systems" on the disk.

The OP asked for "hard drive capacity", which I took to refer to the physical hard drive, not to partitions (file-systems) on the drive. I could be wrong, depending on what the OP actually intends to use the data for.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.