Debugging Sketch Plugins

A better workflow to see logs

James Tang
MagicSketch Blog

--

The Sketch Custom Script panel is the playground for developers custom scripts. The top part is where you type, and the bottom part is the output area for your code.

However once we’re ready to release it to the world and migrate to a plugin bundle, we’ll not be able view logs using the Custom Script panel.

The System Console

The Sketch plugin’s official debugging section describes an expected procedure for developers to use the System’s console app to view logs after they migrated to a plugin bundle.

The problem of the using console app is it’s full of noises. Even though there’s an instruction to help you filter out stuffs, I still find that to be a headache to work with.

Sharing Code

There’s a documented feature in the developer section that’s allows plugins to Share Code between each other.

Doing this sort of thing isn’t generally recommended though. Your plugin will be installed by the user and/or copied into place by Sketch, and you have no guarantees about what other plugins or files are available on the system.

It wasn’t generally recommended as stated, but I found that to be a rescuing feature to fix my headache on viewing logs.

Back to the Custom Script panel

My ideal procedure would be executing my plugin through the Custom Script panel, so that I can see the logs in the output area without switching back and forth to the System Console.

The Sharing Code feature made this possible for developers to do so. You’ll just need to import your plugin’s code inside the panel:

@import 'yourplugin.sketchplugin/Contents/Sketch/file.js' your_triggering_method(context);

Real life example

Since I’ve multiple files in Magic Mirror, I’ll need to import all the dependancies. Note that my plugin is nested in a folder as well.

It works great for me

This technique greatly reduced my development time without needing to go back and forth between Sketch and the System Console. Whenever I made changes, just save the file in my text processor and press “Run” to see the output instantly.

Read more articles in the Sketch Plugin Development series

Originally published at james.ooo on December 8, 2015.

--

--

James Tang
MagicSketch Blog

Sketch Plugins and iOS UX Engineer. Opensource projects contributor, share on Twitter. @jamztang