Update: I'm sure you've all read about Sketch leaving the App Store (more info at http://sketchapp.com/exit). I can't say I'll miss fighting with the sandbox, so I guess it's time to freeze this project : )
A small library to get around sandbox issues in Sketch.
I'll write a real explanation when I have the time, but if you don't know why you need this, this is definitely not for you :)
The library is not heavily tested, so please file an issue if it doesn't work for you :)
-
include the 'sandbox.js' library in your plugin, using
#import 'sandbox.js'
-
ask the user to authorize a path, like this:
new AppSandbox().authorize(path, callback)
where
path
is an absolute path to a folder, andcallback
is a JavaScript function that will be executed if the user authorizes the operation.
- Once a user authorizes a folder, you'll be able to write to its subfolders.
This is my personal favorite way of dealing with sandboxing issues: just ask the user for permission to write to her $HOME folder:
var home_folder = "/Users/" + NSUserName()
new AppSandbox().authorize(home_folder, function(){
// do whatever you need to do here
})
This is probably overkill, unsafe, and unreasonable to ask. But on the other hand, you'll only need the user to authorize Sketch once (regardless of the plugin, authorization is per-app, not per-plugin :). As explained in the Notes section, once the user authorizes its $HOME folder, you'll be able to read & write from its subfolders (including the 'Documents' and 'Dropbox' folders :)