milligramme 3cc

Memo for ( ExtendScript + Script UI ) { InDesign, Illustrator } + Ruby { Web Service }

2011/09/22
by mg
0 comments

[Font]プログラミング用フォント Ricty を生成してみた

プログラミング用フォント Ricty がよさそうだったのでを生成してみました。

準備

Ricty-3.1.1生成プログラムをダウンロード
プログラミング用フォント Ricty

Inconsolata.otf をダウンロード
Inconsolata

Migu 1M をダウンロード
ダウンロード : M+とIPAの合成フォント

fontforgeをインストール

$ brew install fontforge
==> Installing fontforge dependency: gettext
==> Downloading http://ftp.gnu.org/pub/gnu/gettext/gettext-0.18.1.1.tar.gz
######################################################################## 100.0%
==> Downloading patches
######################################################################## 100.0%
######################################################################## 100.0%
==> Patching
patching file gettext-tools/configure
patching file gettext-tools/Makefile.in
==> ./configure --disable-debug --prefix=/usr/local/Cellar/gettext/0.18.1.1 --wi
==> make
==> make install
==> Caveats
This formula is keg-only, so it was not symlinked into /usr/local.

OS X provides the BSD gettext library and some software gets confused if both are in the library path.

Generally there are no consequences of this for you.
If you build your own software and it requires this formula, you'll need
to add its lib & include paths to your build variables:

    LDFLAGS  -L/usr/local/Cellar/gettext/0.18.1.1/lib
    CPPFLAGS -I/usr/local/Cellar/gettext/0.18.1.1/include
==> Summary
/usr/local/Cellar/gettext/0.18.1.1: 368 files, 13M, built in 4.4 minutes
==> Installing fontforge dependency: glib
==> Downloading ftp://ftp.gnome.org/pub/gnome/sources/glib/2.28/glib-2.28.8.tar.
######################################################################## 100.0%
==> Downloading patches
######################################################################## 100.0%
######################################################################## 100.0%
######################################################################## 100.0%
######################################################################## 100.0%
######################################################################## 100.0%
######################################################################## 100.0%
==> Patching
patching file configure.ac
patching file glib-2.0.pc.in
patching file glib/gunicollate.c
patching file glib/gi18n.h
patching file gio/xdgmime/xdgmime.c
patching file gio/gdbusprivate.c
==> ./configure --disable-rebuilds --prefix=/usr/local/Cellar/glib/2.28.8 --with
######################################################################## 100.0%
==> ed - config.h < config.h.ed
==> make
==> make install
Warning: m4 macros were installed to "share/aclocal".
Homebrew does not append "/usr/local/share/aclocal"
to "/usr/share/aclocal/dirlist". If an autoconf script you use
requires these m4 macros, you'll need to add this path manually.
==> Summary
/usr/local/Cellar/glib/2.28.8: 348 files, 11M, built in 3.2 minutes
==> Installing fontforge dependency: pango
==> Downloading http://ftp.gnome.org/pub/GNOME/sources/pango/1.28/pango-1.28.4.t
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/pango/1.28.4 --with-x
==> make install
/usr/local/Cellar/pango/1.28.4: 127 files, 3.9M, built in 57 seconds
==> Installing fontforge dependency: potrace
==> Downloading http://potrace.sourceforge.net/download/potrace-1.9.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/potrace/1.9 --mandir=/usr/local/Cella
==> make install
/usr/local/Cellar/potrace/1.9: 8 files, 240K, built in 12 seconds
==> Installing fontforge
==> Downloading http://downloads.sourceforge.net/project/fontforge/fontforge-sou
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/fontforge/20110222 --enable-double --
==> make
==> make install
==> Caveats
fontforge is an X11 application.

To install the Mac OS X wrapper application run:
    brew linkapps
or:
    ln -s /usr/local/Cellar/fontforge/20110222/FontForge.app /Applications
==> Summary
/usr/local/Cellar/fontforge/20110222: 269 files, 15M, built in 2.5 minutes

ダウンロードした Ricty-3.1.1.tar.gz を展開して、

  • Inconsolata.otf
  • Migu-1M-bold.ttf
  • Migu-1M-regular.ttf

を同じ階層にコピー

同梱されているシェルスクリプトを実行。引数は上記のフォントたち
ricty_generator.sh

$ sh ricty_generator.sh Inconsolata.otf Migu-1M-regular.ttf Migu-1M-bold.ttf
Ricty Generator 3.1.1

Author: Yasunori Yusa 

This script is for generating ``Ricty'' font from Inconsolata and Migu 1M.
It requires 2-5 minutes to generate Ricty. Owing to SIL Open Font License
Version 1.1 section 5, it is PROHIBITED to distribute the generated font.

Generate modified Inconsolata
Open Inconsolata.otf
Generated Modified-Inconsolata-Regular.sfd
While bold-facing Inconsolata, wait a bit, maybe a bit...
Generated Modified-Inconsolata-Bold.sfd
Generate modified Migu 1M
Open Migu-1M-regular.ttf
While scaling Migu-1M-regular.ttf, wait a little...
Generated Modified-Migu-1M-regular.sfd
Open Migu-1M-bold.ttf
While scaling Migu-1M-bold.ttf, wait a little...
Generated Modified-Migu-1M-bold.sfd
Generate Ricty
While merging Modified-Inconsolata-Regular.sfd and Modified-Migu-1M-regular.sfd, wait a little more...
Generated Ricty-Regular.ttf
While merging Modified-Inconsolata-Bold.sfd and Modified-Migu-1M-bold.sfd, wait a little more...
Generated Ricty-Bold.ttf
Remove temporary files
Generated RictyDiscord-Regular.ttf
Generated RictyDiscord-Bold.ttf
Succeeded to generate Ricty!

成功すると4つのフォントが生成される

Ricty の他に Ricty Discord というのが生成されますが、説明によると

派生フォント Ricty Discord
Ricty では、調和・統一感の維持のため、プログラミング用フォントのコアである Inconsolata 由来の ASCII 文字に手を入れないようにしています。Discord (不協和音) 版は、統一感を乱す覚悟で ASCII 文字に手を入れた Ricty の派生フォントです。通常、Ricty Discord は Ricty 生成の際に自動的に生成されますが、パッチスクリプトを直接実行することによっても生成できます。

Ricty と Ricty Discord の比較

Discord の方が文字によって角がたった印象(rとか7とかDとか)、小さいサイズでみるとゴミゴミっぽく感じるのかも(好みだと思うが)。
とりあえず Terminal.app で使っている Menlo Regular のかわりに Ricty Reguler 使ってみた。同じサイズだと 2pt くらい小ぶりにみえるけど、あまり違和感もなく視認性はよさそう。
あと、小文字の g がいわゆる 「お団子g」 なのが個人的には好きだったりする。

TextMateの現在の仕様上、残念ながら使えない。

Bookmark this on Delicious
[Font]プログラミング用フォント Ricty を生成してみたmilligramme 3cc

2011/09/08
by mg
0 comments

[ScriptUI]スクリプト自身にパラメータ埋め込み

ちょっと思いついたので試してみた、ScriptUIでスクリプトファイル本体にパラメータを書き込ませて挙動を変化させる実験。

1行目の mode の値で分岐します。デフォルトでは 0 なので alert で “A” が返ります。

ScriptUIダイアログで押したボタンによって、この mode の値を変えて追記モードで書き込みます。
B のボタンを押すと次回実行時には1行目は var mode = 1; となっていて “B” が返ります。という実験。
書き込むパラメータは複数行でもOK、ただし空行十分に用意しておくこと。

あと、TextMate の ExtendScript Bundleや Python の ind.py などの OSAScript経由で本体を複製して実行するような実行形式だと使えません。
また、ESTK (ExtendScript Toolkit)ではハングアップしてしまいました。

あまり使えませんね。

var mode = 0;

// DON'T write/change anything above here //

// embed param itself test

if (mode === 0) {alert("A");}
else  {alert("B");}

var u;
var w = new Window('dialog', "params", u);
w.orientation = 'column';
w.alignChildren = ['fill', 'fill'];

var a = w.add('button', u, "A");
var b = w.add('button', u, "B");

a.onClick = function () {
  f = File(app.activeScript);
  f.encoding = "UTF-8";
  f.open('e');
  f.seek(0,0);
  f.writeln("var mode = 0;"); // rewrite params
  f.close();
  w.close();
}

b.onClick = function () {
  f = File(app.activeScript);
  f.encoding = "UTF-8";
  f.open('e');
  f.seek(0,0);
  f.writeln("var mode = 1;"); // rewrite params
  f.close();
  w.close();
}

w.show();
Bookmark this on Delicious
[ScriptUI]スクリプト自身にパラメータ埋め込みmilligramme 3cc

2011/09/06
by mg
0 comments

[InDesign]オーバーフローチェック2種比較

InDesignでドキュメントがオーバーフローしてるかしてないかのプリフライト的チェックするのにアプローチの違う2つのもので比べてみた。長体処理とかはしません。

  • ストーリーのオーバーフローをチェックしてしてたら、テキストフレーム(textContainers)を舐める
  • スプレッドごとにテキストフレームを舐めていく

チェックするドキュメントの内容にもよるんだろうけど、ストーリーで攻めた方が速い気がする。
ベンチに $.hiresTimer を使っているのでCS4以降ですが、new Date().getTime()でも全然問題ない(単に使いたかっただけ)
overflow_check_via_story() の方は TextContainer を使っているので CS3以降でないと使えません。

var doc = app.documents[0];
a = $.hiresTimer // ベースの時間
overflow_check_via_story (doc);
b = $.hiresTimer
overflow_check_via_spread (doc);
c = $.hiresTimer
$.writeln(b); // 差分以下同
$.writeln(c);

function overflow_check_via_story (doc) {
  var story_obj = doc.stories;
  var error_overflow = [];

  for (var sti=0, stiL=story_obj.length; sti < stiL ; sti++) {
    if (story_obj[sti].overflows) {
      var tx_container_obj = story_obj[sti].textContainers;
      for (var tci=0, tciL=tx_container_obj.length; tci < tciL ; tci++) {
        if (tx_container_obj[tci].overflows) {
          error_overflow.push(tx_container_obj[tci].parent);
        };
      };
    }
  };
  return error_overflow
}

function overflow_check_via_spread (doc) {
  var spread_obj = doc.spreads;
  var error_overflow2 = [];

  for (var spi=0, spiL=spread_obj.length; spi < spiL ; spi++) {
    var tf_obj = spread_obj[spi].textFrames;
    for (var tci=0, tciL=tf_obj.length; tci < tciL ; tci++) {
      if (tf_obj[tci].overflows) {
        error_overflow2.push(tf_obj[tci].parent);
      };
    };
  }
  return error_overflow2
};
Bookmark this on Delicious
[InDesign]オーバーフローチェック2種比較milligramme 3cc

2011/08/31
by mg
3 Comments

[InDesign]scriptArgsメモ

InDesignでスクリプトの引数?という scriptArgs があるのでためしてみた

/**
 * InDesign Script Argument memo
 */

// スクリプト引数をセットする
app.scriptArgs.set("mori", "girl");
app.scriptArgs.set("hayashi", "boy");

if (app.version.split('.')[0] > 5) {
  $.writeln("is valid?: " + app.scriptArgs.isValid);
  // => true
};
// ゲットする
$.writeln("get value of mori : " +   app.scriptArgs.get("mori") );
// => girl

// 保存する
app.scriptArgs.save();

// 消す
app.scriptArgs.clear();
$.writeln("get value of mori : " +   app.scriptArgs.get("mori") );
// => ""

$.writeln("after clear, is defined? : " + app.scriptArgs.isDefined("mori") );
$.writeln("after clear, is defined? : " + app.scriptArgs.isDefined("hayashi") );
// => false

// リストアする(saveしてないとエラーになる)
app.scriptArgs.restore();
$.writeln("and then restore, is defined? : " + app.scriptArgs.isDefined("mori") );
// => true

$.writeln("get value of mori : " +   app.scriptArgs.get("mori") );
// => girl
$.writeln("get value of hayashi : " +   app.scriptArgs.get("hayashi") );
// => boy

挙動がわかったけど使いどころがわからない

Bookmark this on Delicious
[InDesign]scriptArgsメモmilligramme 3cc

2011/08/25
by mg
0 comments

[git] .gitignore を共有したい

Git を使っていて必ずといっていいほど、.gitignoreに .DS_Store を追加しているのをそろそろ卒業したい。調べてみると ~/.gitconfig に

$ git config --global core.excludesfile ~/.gitignore

的な内容を書き込めば、~/.gitignore に書き込んだ設定を共有できるらしい。

#.gitignore
[user]
	name = milligramme
	email = milligramme.cc@gmail.com
[color]
	ui = auto
[core]
  excludesfile = ~/.gitignore

これで、$ git init 直後に .DS_Store は除外対象になってる
で、ちょっとだけハマったのが、パス。$HOME や `whoami` だと有効にならなかった。

excludesfile = $HOME/.gitignore … 効かない
excludesfile = /Users/`whoami`/.gitignore … 効かない
excludesfile = ~/.gitignore … 効く
excludesfile = /Users/gdansk/.gitignore … 効く(コマンドライン↓で設定したのは全てこれになる)

$ git confing --global core.excludesfile $HOME/.gitignore
$ git confing --global core.excludesfile /Users/`whoami`/.gitignore
$ git confing --global core.excludesfile ~/.gitignore

参考にしたところ

Bookmark this on Delicious
[git] .gitignore を共有したいmilligramme 3cc

2011/08/18
by mg
0 comments

[TextMate]個人的によく使うショートカットメモ

TextMateにビルトインのショートカットと 他のバンドルと共通で使える、Source, Text, TextMateバンドルでよく使うショートカットのメモ
個々のバンドルについては省略。

ショートカットリスト

キーボードショートカットリストを出す(Bundles/TextMate/Show Keyboard Shortcuts)

  command+option+control+k

現在のバンドルのショートカットリスト(Bundles/Select Bundle item…)

  command+control+t

移動・選択

行末まで選択(Edit/Select/line)

  command+shift+l

選択範囲の行移動, 列移動(Text/Move Selection)

  command+control+↑,command+control+↓,
  command+control+→,command+control+←

選択範囲の複製(カーソル挿入の場合は一行複製)(Bundles/Text/Duplicate Line)

  shift+control+d

行削除(Bundles/Text/Delete Line)

  shift+control+k

行連結(空行以外の次の行を連結) (Bundles/Text/Join Line with Next)

  shift+control+j

word単位で移動

  option+←, option+→

word単位で選択

  option+shift+←, option+shift+→

同じインデント階層の行を移動

  option+↑, option+↓

整形

複数行編集(Text/Edit Each line in Selection)

  command+option+a

のあと文字入力、各行行末に同じものが入力される

矩形選択

  option+selection

インデント (Text/Shift Left,Right)

  command+[, command+]

=>や=でそろえる (Bundles/Source/Align Assignments)

  command+option+]

テキスト変換

大文字・小文字変換(Text/Convert/to Uppercase, to Lowercase)

  control+u, control+shift+u

文字を16進数の文字コードに変換(Bundles/Text/Converting/Convert Character to Hex)

  control+shift+x

☁ → 0×2601

プロジェクトモード

プロジェクト内のファイルへ(Navigation/Go to File…)

  command+t

ファイルリストをインクリメンタルサーチ

プロジェクト内検索(Edit/Find/Find in Project)

  command+shift+f

ファイル切り替え(Navigation/Next, Previous File Tab)

  command+shift+[, command+shift+]

おまけ)タブトリガー

isoD[tab] 2011-08-18

lorem[tab] Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

参考にというか他人のよく使うショートカット

Bookmark this on Delicious
[TextMate]個人的によく使うショートカットメモmilligramme 3cc

2011/08/11
by mg
0 comments

[TextMate]Bundleをgit submodule管理に変更

普段コーディングに使っているTextMateのバンドル(.tmbundle)とプラグイン(.tmplugin)の管理を git submodule に変えたのでメモ。

今までは

  • インストールはshellscriptを用意して一気に git clone
  • アップデートはそれぞれのバンドルのディレクトリでgit pullする。

という方法を取っていましたが、 @satococoa さんに git submodule 便利。と教えてもらったので整頓も兼ねて試してみました。

基本的な流れは

  • gitレポジトリ内(Bundlesフォルダ)で、git submodule add [追加したいバンドルの gitリポジトリ]
  • で追加

  • git commit -m "add to submodule" でコミット。これでOK。
  • 更新する場合は git submodule foreach git pull という感じでアップデートがあれば更新してくれる。

やってることはgit pullなんで、bundleをちょこっと自分仕様にいじったときでも、上書きでなくマージになるので安心(なはず)。

まずBundleの方

いっぱいある.tmbundleを各々 git submodule add が面倒なので インストール用のshellscriptを流用してsubmodule化します。

#!/usr/bin/env bash

### Bundles
# cd /Users/`whoami`/Library/Application\ Support/TextMate/Bundles

# ExtendScript Bundle original
# git://github.com/kanemu/extendscript-tmbundle.git
git submodule add git@github.com:milligramme/extendscript-tmbundle.git ExtendScript.tmbundle

# Jsdoc-Toolkit Bundle
git submodule add http://github.com/choan/jsdoctoolkit-tmbundle.git Jsdoctoolkit.tmbundle

# AppleScript Bundle
git submodule add git://github.com/textmate/applescript.tmbundle.git AppleScript.tmbundle

# HTML5
git submodule add git://github.com/johnmuhl/html5.tmbundle.git

# kHTML xhtml
git submodule add git://github.com/kennethreitz/kHTML.tmbundle.git

# Ruby on Rails 3
git submodule add git://github.com/drnic/ruby-on-rails-tmbundle.git "Ruby on Rails.tmbundle"

# Titanium Mobile Bundle
git submodule add git://github.com/subtleGradient/JavaScript-Appcelerator-Titanium-Mobile.tmbundle.git TitaniumMobile.tmbundle

# TextMate Bundle for CoffeeScript
git submodule add git://github.com/jashkenas/coffee-script-tmbundle CoffeeScript.tmbundle

# Handcrafted HAML TextMate bundle
git submodule add git://github.com/handcrafted/handcrafted-haml-textmate-bundle.git HAML-Handcrafted.tmbundle

# SeaofClouds Sass TextMate bundle
git submodule add git://github.com/seaofclouds/sass-textmate-bundle.git "Ruby Saas.tmbundle"

# RSpec
git submodule add git://github.com/rspec/rspec-tmbundle.git RSpec.tmbundle
# open up TextMate Preferences
# go to the Advanced tab
# add a variable named RUBYOPT with the value rubygems

# RDoc
git submodule add git://github.com/joshaven/RDoc.tmbundle.git

# Markdown, Multi Markdown
git submodule add git://github.com/textmate/markdown.tmbundle.git

同様にPluginの方

こちらはTextMateで日本語入力する上で必須の CJK-Input.tmplugin は github上にはないので別途インストール。面倒なのでついでに shellscriptで落としてこれるように。
また、git管理の対象外にしたいので .gitignore にディレクトリを追加しておきます。

#!/usr/bin/env bash

# install CJK-Input.tmplugin

cd $HOME/Desktop
curl -O http://hetima.com/textmate/CJKInput20061110.zip
unzip CJKInput20061110.zip
cp -r CJKInput20061110/CJK-Input.tmplugin /Users/`whoami`/Library/Application\ Support/TextMate/PlugIns/CJK-Input.tmplugin
rm -rf CJKInput20061110.zip CJKInput20061110
rm -rf __MACOSX

2011-08-22
プラグインはsubmoduleではプラグインが動作しないのでやらないことにした
プラグインの subumodule化

#!/usr/bin/env bash

### Plugin
# cd /Users/`whoami`/Library/Application\ Support/TextMate/PlugIns 

# MissingDrawer Plugin for TextMate
git submodule add git://github.com/jezdez/textmate-missingdrawer.git MissingDrawer.tmplugin

更新

自分の場合は平気でしたが、branchがmasterになってないバンドルもあるみたいなので、更新はこんな感じがいいみたい。foreach以降は gitコマンドなんですね。

$ git submodule foreach 'git checkout master; git pull origin master'

長いな。エイリアスつくろう。

参考にしたところ

Bookmark this on Delicious
[TextMate]Bundleをgit submodule管理に変更milligramme 3cc

2011/08/05
by mg
0 comments

[Web]Guard をためす

監視ツールの Guard を試しました。

使い道はいろいろとありそうなのですが、まずは簡単な Sinatra アプリで試します。
Bundler を利用、Webブラウザは Google Chrome、OSXの場合。

ちなみに watchr との違いはよくわかりません

# Gemfile
Develepment 環境に Guard 関係の gem を入力
Growlも使えるみたい。

  source :rubygems

  gem 'sinatra'
  gem 'haml'

  group :development do
    gem 'guard'
    gem 'rb-fsevent' # OSX固有のもの
    gem 'guard-livereload'
    gem 'guard-ego'
  end

# app.rb

  # -*- coding: utf-8 -*-

  get '/' do
    haml :index
  end

# config.ru

  require "bundler"
  Bundler.require

  require "./app.rb"
  run Sinatra::Application

# views/index.haml

  !!! 5
  %html
    %head
      %title title
      %meta{:charset => 'utf-8'}
    %body
      %p Moof

いつもどおりに
$ bundle install し
$ guard init で空の Guardfile が生成される

$ guard init livereload
> livereload guard added to Guardfile, feel free to edit it
でテンプレートが Guardfile に書き込みされる guards が Rails 用なので Sinatra 用のルートを追記する

# Guardfile

  # A sample Guardfile
  # More info at https://github.com/guard/guard#readme

  guard 'livereload' do
    watch(%r{app/.+\.(erb|haml)})
    watch(%r{app/helpers/.+\.rb})
    watch(%r{(public/|app/assets).+\.(css|js|html)})
    watch(%r{(app/assets/.+\.css)\.s[ac]ss}) { |m| m[1] }
    watch(%r{(app/assets/.+\.js)\.coffee}) { |m| m[1] }
    watch(%r{config/locales/.+\.yml})

    # sinatra
    watch(%r{.+\.rb})
    watch(%r{views/.+\.(haml|sass|css)})
  end

Google Chrome 用のExtensionをインストールしておく
LiveReload – Chrome Web Store

guard を起動していないで LiveReload を使おうとすると


LiveReload Cannot connect to LiveReload server:
ws://localhost:35729/websocket
と怒られるので
$ guard して LiveReload ボタンをクリックして有効に、Enable LiveReload だと緑色にかわる

これで Projectフォルダ内の .haml や .sass ファイルをいじるとWebブラウザがリロードしてくれるようになります。便利!
Guardfile を書き換えたら guard の再起動が必要なのですが guard-ego を入れておくと自動的に再起動してくれます。便利!
普通に静的ファイルのときでも使えるので色々試してみたい。

参考にしたところ

Bookmark this on Delicious
[Web]Guard をためすmilligramme 3cc

2011/08/05
by mg
0 comments

[InDesign]セル幅を内容に合わせる

InD_Board セル幅を内容に合わせる
の補足。

セルの内容にあわせてセル幅を調整するというスクリプトです(デザイン処理的にどうこうはおいておいて)。
やってることは、コラムごとにテキストの頭とお尻の位置の差の最大値をセル幅にしてます。
セルの中身がないときとオーバーフローしているときには、この値を取得出来ずにエラーになるのを認識してたんですが面倒だったのでとりあえずポストしました。

表のオーバーフローの処理って、while(セルのオーバーフロー) がうまく認識されないので、親テキストフレームの.recompose()メソッドつかった強制認識的な処理をするのですが、前々からこの処理がイヤで、なんとかならないものかと思ってたのですが、いい案が思いついたのでメモついでにアップ。

具体的には、オーバーフロー中無効になっている lines プロパティが有効になったところで処理を抜けるって感じです。

#target "InDesign"

if (app.selection.length === 1) {
  var sel = app.selection[0];
  if (sel.hasOwnProperty('cells')) {
    // selection 選択した列のみに適用
    main(sel, 2);
  };
};

function main (sel, margin) {
  var col = sel.columns;
  for (var i=0, iL=col.length; i < iL ; i++) {
    var cel = col[i].cells;
    var ar = [];
    for (var j=0, jL=cel.length; j < jL ; j++) {
      // if cell has no content
      if (cel[j].texts[0].contents === "") {continue};
      // if cell overflows
      if (cel[j].overflows) {
        while(cel[j].overflows){
          cel[j].width += 1;
          if (cel[j].properties['lines'] !== undefined) {break;};
        }
      };
      var os_start = cel[j].lines[0].insertionPoints[0].horizontalOffset;
      var os_end = cel[j].lines[0].insertionPoints[-1].horizontalOffset;
      ar.push(os_end - os_start);
    };
    col[i].rightInset = col[i].leftInset = margin * 0.5;
    var padding = col[i].rightInset + col[i].leftInset;
    var line_weight = col[i].rightEdgeStrokeWeight * 0.5 + col[i].leftEdgeStrokeWeight * 0.5;
    col[i].width = ar.sort(function(a,b){return b > a})[0] + padding + line_weight;
  };
}
Bookmark this on Delicious
[InDesign]セル幅を内容に合わせるmilligramme 3cc

2011/07/29
by mg
0 comments

[Web]Pinboard.in の untagged をまとめて削除

SBM には delicious から乗り換えて pinboard.in を使っています。

今回は誤操作で大量のリンクをブックマーク追加してしまったのを削除したときのメモです。

Pinboardの設定項目 settings > twitter

  • Twitterでつぶやいたツイート内のリンクを追加
  • Favしたツイート内のリンクを追加

を有効にして試したところ

適用後のツイートから追加されると思いきや、過去にさかのぼってリンクが大量に追加され、気付くと1400件ほどのリンク(soundtracking や twipic のとか含む)が追加されてしまいました (T_T)。

ブックマークをみてみると

from:twitter from:twitter_favs
というタグ的なものはついているのですが、タグとは違い、抽出して削除するにもそれらしき要素もなく api もそれに対応した項目がないようです。
考えたあげく、タグをつけてないブックマークとほぼ一致することに気付いたのですが、untagged も開発中のようで api 対応してない(T_T)

で、こんな感じで考えてみた
XML書き出し→タグがないブックマークをNokogiriで削除→ブックマークを全削除して再度読み込み

XML書き出し→タグがないブックマークをNokogiriで抽出(削除urlファイル)→shellscriptとして削除urlファイルを実行

Pinboard の APIは
Pinboard API (v1) Documentation

とりあえず全部取得

curl https://USER_ACCOUNT:PASSWORD@api.pinboard.in/v1/posts/all > pinboard.xml

をローカルに xml書出し(open-urlでhttpsがうまくできなかったので、次回トライ)

# -*- coding: utf-8 -*-
require "nokogiri"
require "open-uri"
require "cgi"

user    = "USER_ACCOUNT"
pw      = "PASSWORD"
del_url = "https://"+user+":"+pw+"@api.pinboard.in/v1/posts/delete"

del_url_arr = []
doc = Nokogiri::XML( open("./pinboard.xml") )
doc.xpath('//post[@tag=""]').each do |n|
  del_url_arr << n.attributes['href'].value
end

file = open("pinboard_delete.sh","w")
file.write("#!/usr/bin/env bash\n")
del_url_arr.each do |del|
  durl = CGI.escape(del)
  file.write("curl " + del_url + "?url=#{durl}\n")
end
file.close

Nokogiriでtag=""のurlを抜き出し
「curl で 削除リクエストを url の数だけ出す」 ShellScriptを書き出す↓

curl https://USER_ACCOUNT:PASSWORD@api.pinboard.in/v1/posts/delete?消したいURL

ShellScriptを実行して削除

ものすごくかっこわるいので api が更新されたらまた試してみたい。

Bookmark this on Delicious
[Web]Pinboard.in の untagged をまとめて削除milligramme 3cc