Sketch-PluginHelper
Sketch-PluginHelper copied to clipboard
A sample project that shows how to connect a Sketch 3 plugin to a binary helper app
Sketch-PluginHelper
A sample project that shows how to connect a Sketch 3 plugin to a binary helper app written in Swift.
Test the example plugin
- Extract the contents of this repository in your plugins folder.
- Use the
Make Selection Red
plugin to see an example of custom UI launched by the plugin.
The Helper app
- Open
_source/PluginHelper.xcodeproj
in Xcode. -
SketchPlugin.swift
is a reusable file which you can drop into your own helper app to communicate with Sketch App. -
AppDelegate.swift
contains code to instantiate SketchPlugin, and show the initial window once set up. - Check out
Main.storyboard
andHelloViewController.swift
to see how the custom UI is set up and how it usesSketchPlugin.swift
to load data from and send data to the Sketch App.
Hints
- When developing your Helper app, make sure you have only one
<Helper>.app
file on your system. The plugin script uses the[NSWorkspace openFile: withApplication: andDeactivate:]
method to send commands to the helper app. If there is more than one<Helper>.app
file on your system (even in different folders),NSWorkspace
will be confused about which app bundle it should use to launch the commands, and may use an older version than expected. When you Archive your helper app, remember toMove
(notCopy
) it into the script folder. If you've created multiple archives, either delete or zip them so they aren't directly accessible. Also remember to Clean your Xcode project before testing archived app bundles to make sure the test build generated by Xcode is deleted.
Contributions
If you fork this repository and end up making some useful updates, please do send me pull requests so I can include your work here and give you credit.
Help and Questions
If you run into issues or have any questions, please reach out via Twitter @abynim.
Credits
This example uses XPerformSelector to use the Objective-C-only performSelector
method from Swift.