How to make a file executable in Cocoa

One of the things I need to do in our MacOS Client is make a file I create executable. It took a little reverse engeineering to do it, so here’s the code if anyone else needs to make a file executable in MacOS X Cocoa.


// Set the attributes of the file we've just created which is a little clumsy - you have to create a dictionary of attributes
NSDictionary *attributes;
NSNumber *permissions;
permissions = [NSNumber numberWithUnsignedLong: 493];
attributes = [NSDictionary dictionaryWithObject:permissions forKey:NSFilePosixPermissions];
// This actually sets the permissions
[[NSFileManager defaultManager] setAttributes:attributes ofItemAtPath:filePath error:&error];

Comments 1

Leave a Reply

Your email address will not be published. Required fields are marked *