0

I'm trying to create a plugin for Sketch that creates a folder and a file inside it on a specific location.

Since the sketch plugins are written with JavaScript I've been searching how to create a folder and/or a file with JavaScript, and then think about the path, but i'm stuck, i couldn't find the answer so i decided to open a thread myself.

The question is: How can i create a folder/file with JavaScript? and how i can choose where i put it?

Any feedback is welcome I'm new to posting here and a noob with programming so feel free to redirect me to documentation and/or tutorials that may be useful for my issue.

Ruina
  • 401
  • 2
  • 12
  • you can't. Imagine if any old website could create files and folders on your disk whenever it liked. The security implications would be horrendous. – ADyson Mar 22 '17 at 11:42
  • Thank you for the answer (comment), now i realized what a silly route i was taking, I should use the apple developer methods to do what i want (I think). I can't mark your comment as answer for my question, I don't know why, maybe because it's a comment over my post not an answer. – Ruina Mar 23 '17 at 13:45
  • I've added it as an answer now, if you would like to upvote / accept it (I think you have to wait a few minutes before you can do this). – ADyson Mar 23 '17 at 14:01
  • The up vote won't show since i don't have 15 reputation (really new to the site) but i accept it already thank you again for the explanation. – Ruina Mar 23 '17 at 14:05

2 Answers2

1

The simple answer is you can't. Imagine if any old website could create files and folders on your disk whenever it liked. The security implications would be horrendous.

ADyson
  • 57,178
  • 14
  • 51
  • 63
  • This is possible—see my answer. It is little known because it isn't in Bohemian's API and not documented on their site. This is using the Cocoa API which is only documented on Apple's site. – Subcreation Jan 07 '18 at 20:23
1

This can be done with the user's permission.

AppSandbox provides this functionality for you: https://github.com/bomberstudios/sketch-sandbox/blob/master/sandbox.js

The user is prompted to grant permission to do this the first time they run your plug-in. Every time after, it simply writes the file without interruption.

Subcreation
  • 1,353
  • 12
  • 26