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 Redplugin to see an example of custom UI launched by the plugin.
The Helper app
SketchPlugin.swiftis a reusable file which you can drop into your own helper app to communicate with Sketch App.
AppDelegate.swiftcontains code to instantiate SketchPlugin, and show the initial window once set up.
- Check out
HelloViewController.swiftto see how the custom UI is set up and how it uses
SketchPlugin.swiftto load data from and send data to the Sketch App.
- When developing your Helper app, make sure you have only one
<Helper>.appfile 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>.appfile on your system (even in different folders),
NSWorkspacewill 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 to
Copy) 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.
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.
This example uses XPerformSelector to use the Objective-C-only
performSelector method from Swift.