Skip to content

Instantly share code, notes, and snippets.

Last active Nov 1, 2021
What would you like to do?
Reading/writing a sketch file without opening it
let sketch = require('sketch')
let Document = sketch.Document
let path = "/Users/kgutowski/Downloads/Test.sketch"
let url = NSURL.fileURLWithPath(path)
let externalDoc = MSDocument.alloc().init()
externalDoc.readDocumentFromURL_ofType_error(url, "com.bohemiancoding.sketch.drawing", nil); // Be sure to capture error properly
let jsDoc = Document.fromNative(externalDoc)
let doc = MSDocument.alloc().init()
let url = NSURL.URLWithString('/Users/Kski/Downloads/mysketchfile.sketch')

This comment has been minimized.

Copy link

@humbleCoder1990 humbleCoder1990 commented Oct 30, 2021

Hi Kevin.

I came to your github while searching Swift codes.

You are using "NSURL" in javascript.

How do you access object.c or swift object in Javascript ?

I'm writing app using node.js, I want to call some swift function in node.js


This comment has been minimized.

Copy link
Owner Author

@KevinGutowski KevinGutowski commented Nov 1, 2021

You can’t call swift functions with only node.js. You will need to have your app compiled for MacOS and to have node bundled in it, and then use something like Cocoascript to bridge your JS commands to objective-c. I recommend if you want to write Swift then switch over to writing a Mac app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment