I have an OSX/Objective-C/Cocoa application that wants to spawn external applications, like TextEdit, to edit files created by this app. I'm creating the file by copying it into my ~/Documents directory with:
NSFileManager *defaultManager = [NSFileManager defaultManager]; [defaultManager copyItemAtPath:srcPath toPath:destPath error:&err]; NSDate *sourceModified = [self lastModificationOfFile:srcPath]; NSDictionary * attr = @{ NSFileModificationDate : sourceModified, NSFileImmutable : [NSNumber numberWithBool:NO], NSFilePosixPermissions : [NSNumber numberWithUnsignedLong:0666], }; [defaultManager setAttributes:attr ofItemAtPath:destPath error:nil];When I open this file in TextEdit, the window header says "filename.txt - Locked". Editing the document gives me the "Are you sure you want to modify the document in place?" dialog. I select "Overwrite", but then attempts to save give me "The document "filename.txt" could not be saved. You don't have permission."
However, this writes a "filename.txt.sb-a69dcdc5-7V6D2g" file into my Documents directory. And files created from the bash shell with "echo blablabla > filename.txt" open just fine.
I have tried many variations on those attributes. I cannot see any difference between the files which work and those which display "... - Locked" using "ls -la@ filename.txt" or "xattr", even side-by-side in the same directory.
Clearly I'm up against some sandboxing issue with the files I create, but all of my searches are about the other side of this problem.