Run a script

Sketch can run scripts from two places:

  1. The built-in script editor in the Plugins menu
  2. A JavaScript file bundled with a plugin

1. Write a script using the built-in script editor

The script editor provides full access to the JavaScript API and Internal API.

Run script menu

  1. Open a new or existing file in Sketch
  2. Select Run Script… from the Plugins menu or use the keyboard shortcut control + shift + k to bring up the code editor
  3. Paste in the code below
const sketch = require('sketch')

sketch.UI.message('Hello Sketch 👋')

2. Run the script

Click Run in the script panel or use command + return keyboard shortcut and a message will be shown at the bottom of your Sketch Document window saying Hello Sketch 👋.

Message shows after running the script

3. Save the script as a plugin

Save the script as a plugin to use it later by clicking the Save button in the Run Script… panel.

  1. Enter a name for the plugin, e.g. show message
  2. Click Save

The newly created plugin is now available from the Plugins menu.

The save script is available as a command from the plugins menu

Next Steps

Check out these resources to learn more about plugins.

See something wrong or incomplete? Improve this page.