Skip to content

Instantly share code, notes, and snippets.

@jrrodjr
Last active July 21, 2018 09:42
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrrodjr/b7f8aeb40cad6fe40cf710962fb8e119 to your computer and use it in GitHub Desktop.
Save jrrodjr/b7f8aeb40cad6fe40cf710962fb8e119 to your computer and use it in GitHub Desktop.
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
NSApp.delegate().librariesController().addAssetLibraryAtURL(libURL);
// Refresh the libraries pane silently
libPane.tableView().reloadData();
sketch.message("Library installed!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment