Last active
November 1, 2021 18:30
-
-
Save KevinGutowski/6a8c20cfe08dde97fc3092e9333d768f to your computer and use it in GitHub Desktop.
Reading/writing a sketch file without opening it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
console.log(jsDoc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let doc = MSDocument.alloc().init() | |
let url = NSURL.URLWithString('/Users/Kski/Downloads/mysketchfile.sketch') | |
doc.writeToURL_ofType_options_error(url,"com.bohemiancoding.sketch.drawing",nil,nil) |
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
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