CocoaScript is a bridge providing access to the internal Sketch APIs and macOS frameworks in JavaScript.

From CocoaScript’s README:

CocoaScript is built on top of Apple’s JavaScriptCore, the same JavaScript engine that powers Safari. So when you write in CocoaScript, you are really writing JavaScript.

CocoaScript also includes a bridge which lets you access Apple’s Cocoa frameworks from JavaScript. This means you have a ton wonderful classes and functions you can use in addition to the standard JavaScript library.


The square bracket syntax of Objective-C is converted to dot-syntax in JavaScript. Internally, CocoaScript creates opaque JavaScript proxy objects which have the following attributes:

  • Objective-C properties are exported to JavaScript:
    • Getter:
    • Setter: = 'Sketch'
  • Objective-C selectors are exposed as methods of the JavaScript proxy.
  • : are converted to _, the last underscore is optional.
  • Calling a method with an underscore requires you to double up: sketch_method becomes sketch__method
  • Each component of the selector is concatenated into a single string with no separation.






Some Objective-C selectors require pointer parameters. Since JavaScript does not support passing objects by reference CocoaScript provides MOPointer, a proxy object to create references from variables.

let str = NSMutableString.alloc().init()
let pointer = MOPointer.alloc().initWithValue(str)

str.setString('Hello Sketch')

str.appendString(' 👋')

Use macOS Frameworks

To use a macOS framework, it needs to be imported first. Please note that Foundation and CoreGraphics are imported by default.


let url = NSURL.alloc().initWithString(
let asset = AVAsset.assetWithURL_(url)


Read more about how to use CocoaScript and macOS frameworks.

See something wrong or incomplete? Improve this page.