0

How can I parse .sketch files generated by sketch - mac application?

I know that psd_tools can be used to parse .psd files generated in Adobe Photoshop.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
Bhartendu
  • 199
  • 5
  • 17

3 Answers3

6

I don't have any experience with Sketch, but I downloaded a sample .sketch file and it turned out to be an "SQLite 3.x database". This means you can open it with python's sqlite3 module.

As it happens I had some code lying around that I wrote to inspect another sqlite database, so I took a look: It contains a metadata table and a "payload" table (called metadata and payload, respectively), both of which have just name and value columns. However, the payload table has just one row, and in both tables the values seem to be containers in some other format I don't recognize. So although sqlite3 is the file format, it appears that it is just the outer layer of the onion.

alexis
  • 48,685
  • 16
  • 101
  • 161
  • Well that's a start. Thanks a lot. Will look into it and update my findings here as soon as I can. – Bhartendu Sep 06 '15 at 14:07
  • Hey! I cross checked the info that you gave and I think you hit the spot. The data in `payload` table and in the `metadata` table are of `blob format`. A `Binary Large OBject (BLOB)` is basically a collection of binary data stored as a single entity in a database management system, typically `images`, `audio` or any other `multimedia` file and in this case `image layers`. I think it can be easily parsed into `json` format. I am marking your answer as the correct one. Cheers and thanks for pointing me in the right direction! – Bhartendu Sep 06 '15 at 17:37
  • Glad to hear it! And thanks for the follow-up information. If you get working code that can convert the file to json (and maybe back), please consider posting it here. You can expect others to have the same question in the future. – alexis Sep 06 '15 at 18:13
  • Yeah sure, will do. As soon as I am done writing the script will post the github link here! – Bhartendu Sep 07 '15 at 09:05
  • Any news about hacking .sketch files? – Vlad Tsepelev Mar 08 '16 at 14:40
  • @Vlad, you should direct the question to the OP. I still have nothing to do with Sketch. – alexis Mar 08 '16 at 15:28
  • @Vlad, since I don't think you can see deleted answers: Someone posted links to "the official tool" at http://www.sketchapp.com/tool/, and to an associated [blog post](http://bohemiancoders.tumblr.com/post/89354240665/making-a-toolchain-not-just-a-tool). I've no idea if they might be any use. – alexis Mar 08 '16 at 15:31
  • @VladTsepelev Sorry, I chucked the project I was working on. Anyways the **blogpost** alexis pointed out in above comment is helpful and might guide you in the right direction. – Bhartendu Apr 02 '16 at 07:01
  • @Vlad, I came back to take a look and noticed another deleted question: It contains the hint that the BLOBs contain `plist` files. That's good news, because python comes with [plistlib](https://docs.python.org/3/library/plistlib.html). Give it a try, and please write an answer here with your results if you get anywhere. – alexis Apr 02 '16 at 17:38
1

Edit: The new sketch file format (> 43) is super friendly. It's actually a zip folder in which you have the assets and json files which describe the contents. http://sketchplugins.com/d/87-new-file-format-in-sketch-43

Amirc
  • 11
  • 3
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/16878645) – Lukas Körfer Jul 30 '17 at 22:16
  • @lu.koerfer thanks you, I have fixed my answer. btw, I understood the problem after Petter explained it. – Amirc Jul 30 '17 at 22:18
0

Especially as I am unfamiliar with Sketch I do not know of any equivalents to psd_tools. However, this question might help you. Otherwise, you might need to create your own parser.

Community
  • 1
  • 1
James
  • 13
  • 3
  • Thanks for the help, but what I am looking for is a module specifically in python to parse the `.sketch` file data not to convert it. Have been searching on internet for a while now but have come across only `framerJs` which is in coffeescript. – Bhartendu Sep 05 '15 at 14:22