Last active
July 21, 2018 09:42
-
-
Save jrrodjr/b7f8aeb40cad6fe40cf710962fb8e119 to your computer and use it in GitHub Desktop.
Sketch : Install a file as a library from the plugin resources
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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