Mac Sandboxed Application: CaptureScreenshot Filepath Not Working

Hi there.

I have an issue that I’ve been working on for the last few days and have found no solution as of yet. I’m not sure if this is a Unity bug or if its just the Sandboxing that is required now for Mac AppStore development screwing things up.

Just as background, I used this Unity Forum post to sandbox my app:

In my app, I want the user to take screenshot and save it out to their Pictures folder. To do this, I am calling Application.CaptureScreenshot() as follows:

var picturesPath:String = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures) + "/MyProjectName";
if (!Directory.Exists(picturesPath)) Directory.CreateDirectory(picturesPath);
Application.CaptureScreenshot(picturesPath + "/Screen Shot.png");

When I run this in the Unity editor and in a non-appstore-validated, non-sandboxed build, this works correctly; it saves a screenshot to my Pictures folder for my user name. However, when I validate the app and then sandbox it using the process in the link above, this no longer works. I notice that the “System.Environment.GetFolderPath()” call ends up returning a very long, very odd filepath, which I guess kinda makes sense with the sandboxing. However, if I force picturesPath to be “/Users/” + System.Environment.UserName + “/Pictures/MyProjectName”, the CaptureScreenshot() function does not work after sandboxing (but it works in the editor and non-validated builds).

Because of this, the Mac AppStore rejects this project. Other similar products of ours have the same exact functionality, and they work correctly because sandboxing wasn’t necessary until very recently. I cannot expect my users to go through some really odd (possibly temporary) filepath to find the screenshots they’ve taken, and Mac AppStore probably would disapprove of this anyways.

Has anyone else tried this and found any results that coincide with mine? Has anyone found any solutions to saving out files for the user? Any help would be appreciated, and I’m willing to try out any suggestions. Thanks!

Yay! I get to answer my own question. >.

Have you tried to add to the entitlements?