21
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Sketch3のプラグインを開発する

Posted at

Sketch3はプラグインを自作することができる。

Bohemian Coding - Developer
http://bohemiancoding.com/sketch/support/developer/01-introduction/01.html

プラグイン開発はプロジェクト全体の効率化に繋がるので、チームに一人プラグインが書ける人がいると良いと思った。FFで言えばシーフみたいな感じ。

#開発手順
Sketch3のプラグイン構造は非常に単純である。

name.sketchplugin/Sketch/manifest.json
name.sketchplugin/Sketch/script.cocoascript

基本的にはこのようなディレクトリ構造で2つファイルを用意すればいい。
jsonファイルcocoascriptの2つだ。

まずは、manifest.jsonについて、

#manifest.json

リファレンスを見るとゴチャゴチャ書いてあるが、最低限commandsだけ書いておけば良い。
commandsでは、
・メニューに表示する名前
・押した際に実行するスクリプトファイル
・実行するスクリプトファイルのメソッド名
の3つを書く。

manifest.json
{
  "commands" : [
    {
      "script" : "script.cocoascript",
      "handler" : "onRun",
      "name" : "Script Generator"
    }
  ]
}

これで、Sketch3のメニューから実行する事でscript.cocoascriptのonRunメソッドが呼ばれるようになる。

#script.cocoascript

このファイルは別にscript.cocoascriptという名前でなくても良い。
manifest.jsonで指定すればmain.cocoascriptとかどんな名前でも大丈夫だ。

cocoascriptはjsとObjCが混ざったような言語なのだが、臆することはなくてSketchのPlugin>Custom PluginからSketch3上でcocoascriptを実行することが出来る。

いい感じのが書けたらコピペすればいいのだ。

例:

script.cocoascript
var onRun = function(context) {
 var documentName = context.document.displayName();
 log('The current document is named: ' + documentName);
};

#インストールとアンインストール
##インストール
name.sketchpluginをダブルクリックすればインストールされる。

##アンインストール
Plugins>Reveral plugins folder
からプラグインのインストール先のフォルダが開くので、そこからプラグインをゴミ箱に捨てればOK

21
20
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
21
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?