Instantly share code, notes, and snippets.

What would you like to do?
Sketch : Install a file as a library from the plugin resources
function addLibraryFileFromPlugin(context) {
var sketch = context.api();
var libSourceFile = "libraries/myLibrary.sketch"; // The file with the symbols for your library; should located in the plugin's resources folder
var libSourcePath = context.plugin.urlForResourceNamed(libSourceFile).path();
if(libSourcePath) {
var libURL = NSURL.fileURLWithPath(libSourcePath);
var libPaneIdentifier = MSAssetLibrariesPreferencePane.identifier();
var libPane = MSPreferencesController.sharedController().preferencePanes().objectForKey(libPaneIdentifier);
// Add the Sketch file as a library
// Refresh the libraries pane silently
sketch.message("Library installed!");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment