Skip to content

Instantly share code, notes, and snippets.

@littlebusters
Last active February 15, 2019 06:26
Show Gist options
  • Save littlebusters/b602e85d0988f775cf6c to your computer and use it in GitHub Desktop.
Save littlebusters/b602e85d0988f775cf6c to your computer and use it in GitHub Desktop.
Sketch.app Plugin の開発メモ ref: https://qiita.com/littlebusters/items/b919693f4f3d4c183ce0
$ cp /Volumes/class-dump-3.5/class-dump /usr/local/bin/class-dump
# 含まれるフレームワークすべて
$ class-dump /Applications/Sketch.app
# フレームワークを指定
$ class-dump /Applications/Sketch.app/Contents/Frameworks/CocoaScript.framework
# ファイルとしてホームディレクトリへ書き出す場合
$ class-dump /Applications/Sketch.app > ~/sketch-class-dump.txt
var onRun = function(context) {
var doc = context.document;
var sel = context.selection;
}
// JS Style
var artboards = doc.currentPage().artboards();
if ( 0 < artboards.length() ) {
for ( var i = 0; i < artboards.length(); i++ ) {
log( artboards[i].name() );
log( artboards[i].frame().width() );
log( artboards[i].frame().height() );
log( artboards[i].frame().x() );
log( artboards[i].frame().y() );
}
}
// Obj-c style
var artboards = [[doc currentPage] artboards];
if ( 0 < [artboards count] ) {
for ( var i = 0; i < [artboards count]; i++ ) {
log( [[artboards objectAtIndex:i] name] );
log( [[[artboards objectAtIndex:i] frame] width] );
log( [[[artboards objectAtIndex:i] frame] height] );
log( [[[artboards objectAtIndex:i] frame] x] );
log( [[[artboards objectAtIndex:i] frame] y] );
}
}
var appVer = {}
appVer.full = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
appVer.major = ( appVer.full.split( '.' ) )[0];
appVer.minor = ( appVer.full.split( '.' ) )[1] || 0;
appVer.revision = ( appVer.full.split( '.' ) )[2] || 0;
// JS Style
var currentArtboard = doc.currentPage().currentArtboard();
if ( 0 > currentArtboard.length ) {
log( currentArtboard.name() );
}
// Obj-c style
var artboard = [[doc currentPage] currentArtboard];
if ( 0 < [artboards count] ) {
log( [currentArtboard name] );
}
// JS Style
var doc = context.document;
var currentPage = doc.currentPage();
// Obj-c style
var doc = context.document;
var currentPage = [doc currentPage];
// JS Style
var artboard = MSArtboardGroup.new();
artboard.setName( 'Artboard Name' );
artboard.frame().setX( 0 );
artboard.frame().setY( 0 );
artboard.frame().setWidth( 480 );
artboard.frame().setHeight( 720 );
doc.addLayer( artboard );
// Obj-c style
var artboard = [MSArtboardGroup new];
[artboard setName: 'Artboard Name'];
[[artboard frame] setX: 0];
[[artboard frame] setY: 0];
[[artboard frame] setWidth: 480];
[[artboard frame] setHeight: 720];
[doc addLayer: artboard];
// JS Style
var doc = context.document;
var docPages = doc.pages();
log( docPages.count() ); // ページ数を表示
// Obj-c style
var doc = context.document;
var docPages = [doc pages];
log( [docPages count] ); // ページ数を表示
// JS Style
var currentPage = doc.currentPage();
currentPage.addLayers( NSArray.arrayWithObjects( artboard ) );
// Obj-c Style
var currentPage = [doc currentPage];
[currentPage addLayers:[NSArray arrayWithObjects: artboard]];
// JS Style
var doc = context.document;
doc.addBlankPage();
// Obj-c style
var doc = context.document;
[doc addBlankPage];
// JS Style
doc.showMessage( 'Message' );
// Obj-c style
[doc showMessage: 'Meaasage'];
// JS Style
var doc = context.document;
var currentPage = doc.currentPage();
log( currentPage.name() );
// Obj-c style
var doc = context.document;
var currentPage = [doc currentPage];
log( [currentPage name] );
// JS Style
var userInput = COSAlertWindow.new();
//ダイアログタイトル
userInput.setMessageText( 'Dialog Title' );
// テキストフィールド
userInput.addTextLabelWithValue( 'Text Field Title' );
userInput.addTextFieldWithValue( 'Text Field Placeholder' );
// チェックボックス
var checkbox = NSButton.alloc().initWithFrame( NSMakeRect( 0, 0, 300, 18 ) );
checkbox.setButtonType( NSSwitchButton );
checkbox.setTitle( 'Switch Button Title' );
checkbox.setTag( 'value' );
checkbox.setState( false );
userInput.addAccessoryView( checkbox );
// ラジオボタン
var radiobutton = NSButton.alloc().initWithFrame( NSMakeRect( 0, 0, 300, 18 ) );
radiobutton.setButtonType( NSRadioButton );
radiobutton.setTitle( 'Radio Button Title' );
radiobutton.setTag( 'value' );
radiobutton.setState( true );
userInput.addAccessoryView( radiobutton );
// ボタン
userInput.addButtonWithTitle('OK');
// 実行
userInput.runModal();
// Obj-c style
var userInput = [COSAlertWindow new];
//ダイアログタイトル
[userInput setMessageText:'Dialog Title'];
// テキストフィールド
[userInput addTextLabelWithValue:'Text Field Title'];
[userInput addTextFieldWithValue:'Text Field Placeholder'];
// チェックボックス
var checkbox = [[NSButton alloc] initWithFrame:NSMakeRect( 0, 0, 300, 18 )];
[checkbox setButtonType:NSSwitchButton];
[checkbox setTitle: 'Switch Button Title'];
[checkbox setTag: 'value'];
[checkbox setState: false];
[userInput addAccessoryView: checkbox];
// ラジオボタン
var radiobutton = [[NSButton alloc] initWithFrame:NSMakeRect( 0, 0, 300, 18 )];
[radiobutton setButtonType: NSRadioButton];
[radiobutton setTitle: 'Radio Button Title'];
[radiobutton setTag: 'value'];
[radiobutton setState: true];
[userInput addAccessoryView: radiobutton];
// ボタン
[userInput addButtonWithTitle: 'OK'];
// 実行
[userInput runModal];
// JS Style
var doc = context.document;
var currentPage = doc.currentPage();
currentPage.setName( 'Page Name' );
// Obj-c style
var doc = context.document;
var currentPage = doc.currentPage();
[[currentPage] setName:'Page Name'];
// JS Style
var userInput = doc.askForUserInput_initialValue( 'Message', 'Default Value' );
// Obj-c style
var position = [doc askForUserInput: 'Message' initialValue: 'Default Value'];
// JS Style
var doc = context.document;
var artboards = doc.currentPage().artboards();
if ( 0 < artboards.count() ) {
for ( var i = 0; i < artboards.count(); i++ ) {
log( artboards[i].name() );
log( artboards[i].frame().width() );
log( artboards[i].frame().height() );
log( artboards[i].frame().x() );
log( artboards[i].frame().y() );
}
}
// Obj-c style
var doc = context.document;
var artboards = [[doc currentPage] artboards];
if ( 0 < [artboards count] ) {
for ( var i = 0; i < [artboards count]; i++ ) {
log( [[artboards objectAtIndex:i] name] );
log( [[[artboards objectAtIndex:i] frame] width] );
log( [[[artboards objectAtIndex:i] frame] height] );
log( [[[artboards objectAtIndex:i] frame] x] );
log( [[[artboards objectAtIndex:i] frame] y] );
}
}
// JS Style
var doc = context.document;
var currentArtboard = doc.currentPage().currentArtboard();
if ( 0 > currentArtboard.count() ) {
log( currentArtboard.name() );
}
// Obj-c style
var doc = context.document;
var artboard = [[doc currentPage] currentArtboard];
if ( 0 < [artboards count] ) {
log( [currentArtboard name] );
}
// JS Style
var doc = context.document;
var artboard = MSArtboardGroup.new();
artboard.setName( 'Artboard Name' );
artboard.frame().setX( 0 );
artboard.frame().setY( 0 );
artboard.frame().setWidth( 480 );
artboard.frame().setHeight( 720 );
doc.addLayer( artboard );
// Obj-c style
var doc = context.document;
var artboard = [MSArtboardGroup new];
[artboard setName: 'Artboard Name'];
[[artboard frame] setX: 0];
[[artboard frame] setY: 0];
[[artboard frame] setWidth: 480];
[[artboard frame] setHeight: 720];
[doc addLayer: artboard];
var doc = context.document;
var artboard = doc.currentPage().currentArtboard();
var grid = MSSimpleGrid.new();
grid.setGridSize( 16 );
artboard.grid = grid;
// 選択しているシェイプの構造をログで出力
var sel = context.selection;
var shape = sel[0];
log( shape.frame().treeAsDictionary() );
// JS Style
var currentPage = doc.currentPage();
currentPage.addLayers( NSArray.arrayWithObjects( artboard ) );
// Obj-c Style
var currentPage = [doc currentPage];
[currentPage addLayers:[NSArray arrayWithObjects: artboard]];
var doc = context.document;
var artboard = doc.currentPage().currentArtboard();
var grid = MSSimpleGrid.new();
grid.setGridSize( 16 );
artboard.grid = grid;
var doc = context.document;
var artboard = doc.currentPage().currentArtboard();
var vRuler = artboard.verticalRulerData();
var hRuler = artboard.horizontalRulerData();
vRuler.addGuideWithValue( 100 ); // 垂直
hRuler.addGuideWithValue( 100 ); // 水平
var doc = context.document;
var artboard = doc.currentPage().currentArtboard();
var grid = MSSimpleGrid.new();
grid.setGridSize( 16 );
artboard.grid = grid;
var doc = context.document;
var artboard = doc.currentPage().currentArtboard();
var group = MSLayerGroup.new();
group.setName( 'Group Name' );
artboard.addLayers( [group] );
var doc = context.document;
var artboard = doc.currentPage().currentArtboard();
var rectangle = MSRectangleShape.new();
rectangle.name = 'Layer Name';
rectangle.frame().x = 0;
rectangle.frame().y = 0;
rectangle.frame().width = 100;
rectangle.frame().height = 150;
var shape = MSShapeGroup.shapeWithPath( rectangle );
artboard.addLayers( [shape] );
var doc = context.document;
var artboard = doc.currentPage().currentArtboard();
var bezierPath = NSBezierPath.bezierPath();
bezierPath.moveToPoint( NSMakePoint( 0, 0 ) ); // パスを開始する座標
// 直線を引く
bezierPath.lineToPoint( NSMakePoint( 50, 50 ) ); // アンカーポイントの座標
// 曲線を引く
var ancher = NSMakePoint( 200, 200 ); // アンカーポイントの座標
var currentHandle = NSMakePoint( 150, 200 ); // 作成するアンカーポイントのハンドルの座標
var prevHandle = NSMakePoint( 50, 100 ); // 元のアンカーポイントのハンドルの座標
// 曲線を生成
[bezierPath curveToPoint:ancher controlPoint1:prevHandle controlPoint2:currentHandle];
// パスを閉じる
bezierLine.closePath();
var shape = MSShapeGroup.shapeWithBezierPath( bezierPath );
artboard.addLayers( [shape] ); // ベジェシェイプをアートボードへ追加
var doc = context.document;
var artboard = doc.currentPage().currentArtboard();
// マスクの影響を抑える為にグループを作成
var group = MSLayerGroup.new();
group.setName( 'Mask Group' );
// グループ内にマスクの矩形を作成
var maskRect = MSRectangleShape.new();
maskRect.name = 'Mask';
maskRect.frame().x = 0;
maskRect.frame().y = 0;
maskRect.frame().width = 100;
maskRect.frame().height = 150;
var mask = MSShapeGroup.shapeWithPath( maskRect );
group.addLayers( [mask] );
// マスク化
mask.setHasClippingMask( true );
// マスク化による親レイヤーの境界や座標を更新
var doc = context.document;
var artboard = doc.currentPage().currentArtboard();
// 読み込むファイルのパスを設定
var filePath = '/Users/USERNAME/file/to/path.png';
var image = NSImage.new().initWithContentsOfFile( filePath );
var imageData = MSImageData.alloc().initWithImage_convertColorSpace_(image, true);
var bitmap = MSBitmapLayer.new();
bitmap.image = imageData;
bitmap.name = 'Imported Bitmap';
bitmap.frame().x = 0;
bitmap.frame().y = 0;
artboard.addLayers( [bitmap] );
var doc = context.document;
var artboard = doc.currentPage().currentArtboard();
var slice = MSSliceLayer.new();
slice.name = 'Slice Name';
slice.frame().x = 0;
slice.frame().y = 0;
slice.frame().width = 100;
slice.frame().height = 150;
artboard.addSlice( slice );
// Rectangleツールで作成した矩形を選択した状態で
var sel = context.selection;
var rect = sel.firstObject().layers().firstObject();
rect.cornerRadiusFloat = 10;
// 個別にRadiusを設定する場合は次の通り
// rect.cornerRadiusString = "7/0/0/10";
{
"<class>" = MSRect;
constrainProportions = 0;
height = 159;
width = 145;
x = 179;
y = 169;
}
// 選択しているシェイプの構造をログで出力
var sel = context.selection;
var shape = sel[0];
log( shape.frame().treeAsDictionary() );
// 矩形レイヤー(rectangle)を作成したのち
var contextSettings = rectangle.style().contextSettings();
contextSettings.blendMode = 1;
// Blending Modeの設定のコードの後に
contextSettings.opacity = 0.5; // 0から1の値
// 矩形レイヤー(rectangle)を作成したのち
// Fillを追加してプロパティを取得
var fill = rectangle.style().addStylePartOfType( 0 );
// Fillに適用するカラーを設定
var color = MSImmutableColor.colorWithSVGString( '#ff0000' );
color.alpha = 0.8;
// Fillにカラーを適用
fill.color = color;
var openPanel = NSOpenPanel.openPanel();
openPanel.setTitle( "Choose a JSON File" ); // ダイアログのタイトル
openPanel.setCanCreateDirectories = false; // ディレクトリの作成を許可するか
openPanel.setCanChooseFiles = true; // ファイル選択を許可するか
var fileTypes = ['json']; // 選択できるファイルタイプを設定
var openPanelButtonPressed = openPanel.runModalForDirectory_file_types_( nil, nil, fileTypes );
if ( openPanelButtonPressed == NSFileHandlingPanelOKButton ) {
var filePath = openPanel.URL().path();
var json = JSON.parse( NSString.stringWithContentsOfFile( filePath ) );
log( 'Open File from: ' + filePath );
} else {
return false;
}
// 矩形レイヤー(rectangle)を作成したのち
// Fillを追加してプロパティを取得
var fill = rectangle.style().addStylePartOfType( 0 );
// Fillの種類をGradientに変更
fill.setFillType( 1 );
// Gradientプロパティを取得
var gradient = fill.gradient();
// Gradient Typeの設定 / 0: Linear / 1: Radial / 2: Angular
gradient.setGradientType( 0 );
// Gradient Stopを追加 / value: 0..1
gradient.addStopAtLength( 0.5 );
// Gradient Stopに適用するカラーと透明度を設定
var gradientColor = MSImmutableColor.colorWithSVGString( '#ff0000' );
gradientColor.alpha = 0.8;
// Gradient Stopにカラーを適用
gradient.setColor_atIndex_( gradientColor, 1 );
// Gradient Stopの位置を設定
gradient.setPoint_atIndex_( CGPointMake( 1, 1 ), 1 );
var fillCollection = shapeFill.documentData().images();
fill.setPatternImage_collection_( patternPath, fillCollection );
// 矩形レイヤー(rectangle)を作成したのち
// Fillを追加してプロパティを取得
var fill = rectangle.style().addStylePartOfType( 0 );
// Fillの種類をPatternに変更
fill.setFillType( 4 );
// 整列方法を設定 / 0: Tile / Fill: 1
fill.setPatternFillType( 1 );
// パターン画像のパスから画像データを作ってFillへ設定する
var imageData = MSImageData.alloc().initWithImage_convertColorSpace_( '/file/to/path/document.png', false );
fill.setImage( imageData );
// 矩形レイヤー(rectangle)を作成したものとする
// Fillを追加してプロパティを取得
var fill = rectangle.style().addStylePartOfType( 0 );
// Fillの種類をNoiseに変更
fill.fillType = 5; // fill.setFillType( 5 )でもOK
// ノイズの種類を指定 / 0: Original / 1: Black / 2: White / 3: Color
fill.noiseIndex = 3;
// IntensityはOpacityとして設定する
fill.contextSettings().opacity = 0.5;
var openPanel = NSOpenPanel.openPanel();
openPanel.setTitle( "Choose a JSON File" ); // ダイアログのタイトル
openPanel.setCanCreateDirectories = false; // ディレクトリの作成を許可するか
openPanel.setCanChooseFiles = true; // ファイル選択を許可するか
var fileTypes = ['json']; // 選択できるファイルタイプを設定
var openPanelButtonPressed = openPanel.runModalForDirectory_file_types_( nil, nil, fileTypes );
if ( openPanelButtonPressed == NSFileHandlingPanelOKButton ) {
var filePath = openPanel.URL().path();
var json = JSON.parse( NSString.stringWithContentsOfFile( filePath ) );
log( 'Open File from: ' + filePath );
} else {
return false;
}
// 矩形 rectangle を作成済みとして
// 2: ドロップシャドウ / 3: インナーシャドウ
var effect = addStylePart( rectangle, 2 );
// ぼかしの大きさ
effect.blurRadius = 10;
// XY座標
effect.offsetX = 0;
effect.offsetY = 0;
// スプレッドの大きさ
effect.spread = 0;
// 色と不透明度
var color = MSImmutableColor.colorWithSVGString( getHexColor( attrs[i].ShadowColor ) );
color.alpha = getOpacity( attrs[i].ShadowColor );
effect.color = color;
var fillCollection = shapeFill.documentData().images();
fill.setPatternImage_collection_( patternPath, fillCollection );
// 矩形レイヤー(rectangle)を作成したものとする
var effect = rectangle.style().blur();
// ぼかし効果を有効化
effect.isEnabled = 1;
// 0: ガウス / 1: モーション / 2: ズーム / 3: バックグラウンド(多分)
effect.type = 2;
// ぼかしの大きさ
effect.radius = 10;
var doc = context.document;
var artboard = doc.currentPage().currentArtboard();
var text = MSTextLayer.new();
// 0: Auto(デフォルト) / 1: テキストボックスの幅を固定
text.textBehaviour = 1;
// テキストに文字列を入れる
text.stringValue = 'テキストの内容だよ';
// フォントサイズの設定
text.fontSize = '24';
// フォントの設定(Postscript名で指定する)
text.fontPostscriptName = 'フォント名';
// テキストカラーの設定
text.textColor = MSImmutableColor.colorWithSVGString( '#ff0000' );
// テキストボックスの大きさを最適化
text.adjustFrameToFit();
// パラグラフを設定する
var pragraph = NSMutableParagraphStyle.new();
pragraph.minimumLineHeight = 12;
pragraph.maximumLineHeight = 24;
text.addAttribute_value_( NSParagraphStyleAttributeName, pragraph );
// テキストの揃え - 0: 左 / 1: 右 / 2: 中央
text.setTextAlignment( 0 );
// サイズや位置、レイヤー名なども設定できます
artboard.addLayers( [text] );
var openPanel = NSOpenPanel.openPanel();
openPanel.setTitle( "Choose a JSON File" ); // ダイアログのタイトル
openPanel.setCanCreateDirectories = false; // ディレクトリの作成を許可するか
openPanel.setCanChooseFiles = true; // ファイル選択を許可するか
var fileTypes = ['json']; // 選択できるファイルタイプを設定
var openPanelButtonPressed = openPanel.runModalForDirectory_file_types_( nil, nil, fileTypes );
if ( openPanelButtonPressed == NSFileHandlingPanelOKButton ) {
var filePath = openPanel.URL().path();
var json = JSON.parse( NSString.stringWithContentsOfFile( filePath ) );
log( 'Open File from: ' + filePath );
} else {
return false;
}
// 変更する範囲を作成(0文字から2文字目まで)
var range = NSMakeRange( 0, 2 );
// フォント名をサイズを指定
var textFont = NSFont.fontWithName_size_( 'フォント名(Postscript)', 24 );
// 色を指定
var color = MSImmutableColor.colorWithSVGString( '#ff0000' );
// 一部の変更を実行
text.setIsEditingText( true );
text.addAttribute_value_forRange_( NSFontAttributeName, textFont, range );
text.addAttribute_value_forRange_( NSForegroundColorAttributeName, color, range );
text.setIsEditingText( false );
// パラグラフも設定できますが、多分一部だけを変えることはないでしょうね
text.addAttribute_value_forRange_( NSParagraphStyleAttributeName, pragraph, range );
// 選択しているシェイプの構造をログで出力
var sel = context.selection;
var shape = sel[0];
log( shape.frame().class().mocha().instanceMethods() );
{
"<class>" = MSRect;
constrainProportions = 0;
height = 159;
width = 145;
x = 179;
y = 169;
}
MSSymbolMaster.convertArtboardToSymbol( artboard );
// artboard = あらかじめ作成していたアートボード
var symbols['symbolName'] = MSSymbolMaster.convertArtboardToSymbol( artboard );
var openPanel = NSOpenPanel.openPanel();
openPanel.setTitle( "Choose a JSON File" ); // ダイアログのタイトル
openPanel.setCanCreateDirectories = false; // ディレクトリの作成を許可するか
openPanel.setCanChooseFiles = true; // ファイル選択を許可するか
var fileTypes = ['json']; // 選択できるファイルタイプを設定
var openPanelButtonPressed = openPanel.runModalForDirectory_file_types_( nil, nil, fileTypes );
if ( openPanelButtonPressed == NSFileHandlingPanelOKButton ) {
var filePath = openPanel.URL().path();
var json = JSON.parse( NSString.stringWithContentsOfFile( filePath ) );
log( 'Open File from: ' + filePath );
} else {
return false;
}
var doc = context.document;
var cp = doc.currentPage();
for( var i = 0; i < doc.pages().count(); i++ ) {
if( 'Symbols' == doc.pages()[i].name() ) {
var symbolsPage = doc.pages()[i];
break;
}
}
var symbolInstance = symbolsPage.artboards()[0].newSymbolInstance();
symbolInstance.setName( 'Symbol Instance' );
symbolInstance.frame().x = 0;
symbolInstance.frame().y = 100;
cp.addLayers( [symbolInstance] );
var openPanel = NSOpenPanel.openPanel();
openPanel.setTitle( "Choose a JSON File" ); // ダイアログのタイトル
openPanel.setCanCreateDirectories = false; // ディレクトリの作成を許可するか
openPanel.setCanChooseFiles = true; // ファイル選択を許可するか
var fileTypes = ['json']; // 選択できるファイルタイプを設定
var openPanelButtonPressed = openPanel.runModalForDirectory_file_types_( nil, nil, fileTypes );
if ( openPanelButtonPressed == NSFileHandlingPanelOKButton ) {
var filePath = openPanel.URL().path();
var json = JSON.parse( NSString.stringWithContentsOfFile( filePath ) );
log( 'Open File from: ' + filePath );
} else {
return false;
}
// JS Style
doc.showMessage( 'Message' );
// Obj-c style
[doc showMessage: 'Meaasage'];
// JS Style
var userInput = COSAlertWindow.new();
//ダイアログタイトル
userInput.setMessageText( 'Dialog Title' );
// テキストフィールド
userInput.addTextLabelWithValue( 'Text Field Title' );
userInput.addTextFieldWithValue( 'Text Field Placeholder' );
// チェックボックス
var checkbox = NSButton.alloc().initWithFrame( NSMakeRect( 0, 0, 300, 18 ) );
checkbox.setButtonType( NSSwitchButton );
checkbox.setTitle( 'Switch Button Title' );
checkbox.setTag( 'value' );
checkbox.setState( false );
userInput.addAccessoryView( checkbox );
// ラジオボタン
var radiobutton = NSButton.alloc().initWithFrame( NSMakeRect( 0, 0, 300, 18 ) );
radiobutton.setButtonType( NSRadioButton );
radiobutton.setTitle( 'Radio Button Title' );
radiobutton.setTag( 'value' );
radiobutton.setState( true );
userInput.addAccessoryView( radiobutton );
// ボタン
userInput.addButtonWithTitle('OK');
// 実行
userInput.runModal();
// Obj-c style
var userInput = [COSAlertWindow new];
//ダイアログタイトル
[userInput setMessageText:'Dialog Title'];
// テキストフィールド
[userInput addTextLabelWithValue:'Text Field Title'];
[userInput addTextFieldWithValue:'Text Field Placeholder'];
// チェックボックス
var checkbox = [[NSButton alloc] initWithFrame:NSMakeRect( 0, 0, 300, 18 )];
[checkbox setButtonType:NSSwitchButton];
[checkbox setTitle: 'Switch Button Title'];
[checkbox setTag: 'value'];
[checkbox setState: false];
[userInput addAccessoryView: checkbox];
// ラジオボタン
var radiobutton = [[NSButton alloc] initWithFrame:NSMakeRect( 0, 0, 300, 18 )];
[radiobutton setButtonType: NSRadioButton];
[radiobutton setTitle: 'Radio Button Title'];
[radiobutton setTag: 'value'];
[radiobutton setState: true];
[userInput addAccessoryView: radiobutton];
// ボタン
[userInput addButtonWithTitle: 'OK'];
// 実行
[userInput runModal];
// JS Style
var userInput = doc.askForUserInput_initialValue( 'Message', 'Default Value' );
// Obj-c style
var position = [doc askForUserInput: 'Message' initialValue: 'Default Value'];
var openPanel = NSOpenPanel.openPanel();
openPanel.setTitle( "Choose a JSON File" ); // ダイアログのタイトル
openPanel.setCanCreateDirectories = false; // ディレクトリの作成を許可するか
openPanel.setCanChooseFiles = true; // ファイル選択を許可するか
var fileTypes = ['json']; // 選択できるファイルタイプを設定
var openPanelButtonPressed = openPanel.runModalForDirectory_file_types_( nil, nil, fileTypes );
if ( openPanelButtonPressed == NSFileHandlingPanelOKButton ) {
var filePath = openPanel.URL().path();
var json = JSON.parse( NSString.stringWithContentsOfFile( filePath ) );
log( 'Open File from: ' + filePath );
} else {
return false;
}
var openPanel = NSOpenPanel.openPanel();
openPanel.setTitle( "Choose a JSON File" ); // ダイアログのタイトル
openPanel.setCanCreateDirectories = false; // ディレクトリの作成を許可するか
openPanel.setCanChooseFiles = true; // ファイル選択を許可するか
var fileTypes = ['json']; // 選択できるファイルタイプを設定
var openPanelButtonPressed = openPanel.runModalForDirectory_file_types_( nil, nil, fileTypes );
if ( openPanelButtonPressed == NSFileHandlingPanelOKButton ) {
var filePath = openPanel.URL().path();
var json = JSON.parse( NSString.stringWithContentsOfFile( filePath ) );
log( 'Open File from: ' + filePath );
} else {
return false;
}
var fontList = NSFontManager.sharedFontManager().availableFontFamilies();
var fontFamilies = NSFontManager.sharedFontManager().availableMembersOfFontFamily('Helvetica Neue');
var fontFamilies = NSFontManager.sharedFontManager().availableMembersOfFontFamily('Helvetica Neue');
var fontList = NSFontManager.sharedFontManager().availableFontFamilies();
var data = NSJSONSerialization.dataWithJSONObject_options_error_(fontList, 0, nil);
var json = NSString.alloc().initWithData_encoding_(data, 4);
var fontList = NSFontManager.sharedFontManager().availableFontFamilies();
var data = NSJSONSerialization.dataWithJSONObject_options_error_(fontList, 0, nil);
var json = NSString.alloc().initWithData_encoding_(data, 4);
// 選択しているシェイプの構造をログで出力
var sel = context.selection;
var shape = sel[0];
log( shape.frame().class().mocha().instanceMethods() );
(
"<MOMethodDescription: 0x6100004266c0 : selector=makeOriginIntegral, typeEncoding=v16@0:8>",
"<MOMethodDescription: 0x610000426700 : selector=makeRectIntegral, typeEncoding=v16@0:8>",
// 長いため中略
"<MOMethodDescription: 0x610000428260 : selector=setOrigin:, typeEncoding=v32@0:8{CGPoint=dd}16>",
"<MOMethodDescription: 0x610000428300 : selector=setRect:, typeEncoding=v48@0:8{CGRect={CGPoint=dd}{CGSize=dd}}16>"
)
// プロパティのダンプ
var sel = context.selection;
var shape = sel[0];
log( shape.frame().class().mocha().properties() );
(
"<MOMethodDescription: 0x6100004266c0 : selector=makeOriginIntegral, typeEncoding=v16@0:8>",
"<MOMethodDescription: 0x610000426700 : selector=makeRectIntegral, typeEncoding=v16@0:8>",
// 長いため中略
"<MOMethodDescription: 0x610000428260 : selector=setOrigin:, typeEncoding=v32@0:8{CGPoint=dd}16>",
"<MOMethodDescription: 0x610000428300 : selector=setRect:, typeEncoding=v48@0:8{CGRect={CGPoint=dd}{CGSize=dd}}16>"
)
// プロパティのダンプ
var sel = context.selection;
var shape = sel[0];
log( shape.frame().class().mocha().properties() );
PLUGINNAME.sketchplugin
└ Contents
└ Sketch
├ SCRIPT.sketchscript
└ manifest.json
@import 'lib/script.js';
PLUGINNAME.sketchplugin
└ Contents
└ Sketch
├ SCRIPT.sketchscript
└ manifest.json
@import 'lib/script.js';
// JS Style
var currentPage = doc.currentPage();
currentPage.setName( 'Page Name' );
// Obj-c style
var currentPage = doc.currentPage();
[[currentPage] setName:'Page Name'];
{
"author": "littlebusters", // プラグインマネージャーで表示
"menu" : {
"isRoot" : false, // Pluginsメニュー直下へ表示するかどうか
"shortcut" : "",
"items" : [ // メニュー上の並びを設定。commands[INDEX].identifierを指定する。3.3では無効
"css-sprite-mixin-scss",
"css-sprite-mixin-sass",
"css-sprite-mixin-less",
"-", // 3.4.1より、ハイフンを入れるとセパレータとして表示されるように
"css-sprite-mixin-stylus"
],
"title" : "Sketch CSS Sprite Mixin" // Pluginsメニューでのフォルダ名
},
"identifier": "net.creative-tweet.css-sprite-mixin",
"version": "1.1.0", // プラグインマネージャーで表示
"description" : "Generate a code of CSS Sprite Mixin to Clipboard in Sketch.", // プラグインマネージャーで表示
"name" : "Sketch CSS Sprite Mixin", // プラグインマネージャー上の名前。指定しない場合は、ファイル名から取得される
"commands" : [
{
"name": "Scss", // Pluginsメニュー上の表示
"identifier": "css-sprite-mixin-scss",
"handler" : "getScss", // 下のscript内にあるメソッドを指定
"script": "css-sprite-mixin.sketchscript" // スクリプトファイルを指定
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment