LoginSignup
3
2

More than 5 years have passed since last update.

Sketchプラグインの作成に挑戦して見る

Last updated at Posted at 2016-08-24

今朝Mediumを見ていたら初心者向けのSketchPluginの作り方の記事があったので翻訳。

参考記事1
参考記事2

基本的にCocoaScriptで作る。(ObjectiveC/Cocoa + Javascript)

所定の場所にjsonファイルとjsファイル、2つのファイルを用意し、
jsonファイルには基本的な情報、
jsファイルにはどういった挙動をするかを入力指定指定する

{
 “name” : “My Plugin”,
 “identifier” : “my.plugin”,
 “version” : “1.0”,
 “description” : “My First Sketch Plugin”,
 “authorEmail” : “your@email.com”,
 “author” : “Your Name”,

 “commands” : [
     {
         “script” : “MyScript.js”,
         “handler” : “onRun”,
         “shortcut” : “command shift y”,//ショートカットキーを指定できる
         “name” : “Get Page Names”,
         “identifier” : “my.plugin.pagenames”
     }
 ],
}
var onRun = function(context) {

 //reference the Sketch Document
 var doc = context.document;

 //reference all the pages in the document in an array
 var pages = [doc pages];

 //loop through the pages of the document
 for (var i = 0; i < pages.count(); i++){

     //reference each page
     var page = pages[i];

     //get the name of the page
     var pageName = [page name];

     //show the page name in the console
     log(pageName);
 }
}

スクリーンショット 2016-08-24 19.10.28.png

これだけで、Sketchファイルを開いてみると自分のプラグインが表示されると思います。
ショートカットも指定できたりしています。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2