Objective-C - Check FileVault status in OS X

481 views Asked by At

I am working on a Cocoa application (Objective-C) where it needs to determine if the FileVault is turned on. I tried searching the .plist for FileVault but no success.

Any help would be appreciated,

Thanks in advance :) cheers

1

There are 1 answers

1
l'L'l On BEST ANSWER

It's fairly simple via NSTask:

@autoreleasepool {
    NSTask *task = [[NSTask alloc] init];
    [task setLaunchPath:@"/usr/bin/fdesetup"];
    [task setArguments:[NSArray arrayWithObjects:@"status", nil]];

    NSPipe *pipe = [NSPipe pipe];
    [task setStandardOutput: pipe];

    NSFileHandle *file = [pipe fileHandleForReading];
    [task launch];

    NSData *data = [file readDataToEndOfFile];
    NSString *string = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];

    NSLog (@"%@", string); // FileVault is Off/On.
}

There's likely a way to check via SecKeychain, although for a quick check that might be overkill.