I'm developing a sandboxed application, which should run some scripts and following sandboxing rules, those should be located in "~/Library/Application Scripts/com.mydomain.myapp". The application also tries to be friendly to users and offer them to "install" predefined scripts (bundled in the application package) into that folder. To gain access to the application script folder, I use standard method of the NSFileManager, so the code looks something like:
NSError *error;
NSURL *scriptsFolder = [[NSFileManager defaultManager] URLForDirectory:NSApplicationScriptsDirectory
inDomain:NSUserDomainMask
appropriateForURL:nil
create:YES
error:&error]This works fine if the scripts subfolder already exists. However, it if doesn't, the application can't create it. If I pass "NO" as fourth parameter I get back the url, but it's useless (it contains only the path), since the folder is nonexistent. If I pass "YES" as fourth parameter, so that the folder is created if necessary, I get the following error:
Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission to save the file “com.mydomain.myapp”
in the folder “Application Scripts”."
UserInfo={NSFilePath=/Users/milke/Library/Application Scripts/com.mydomain.myapp,
NSUnderlyingError=0x608000259bf0 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}Is there any way to create "com.mydomain.myapp" subfolder inside "Application Scripts" folder without defining temporary exception entitlement or explicitly prompting user to create it him/herself? If not, should this be considered a bug?
On a related note, when I started implementing and testing this feature, the folder "com.mydomain.myapp" was already in the "Application Scripts". When do those applications specific script subfolders get created and by which process? Once I've deleted it I can't seem to make the system to create it again.
Thanks for any info.
-- Dragan