How My Heart Sings

Tue, 14 Jun 2005

CotEditor用のスクリプトを書いてみるそのに

CotEditor用のスクリプトを書いてみる。の続きをもうちょっとだけ。

今まで試してきたスクリプトはどれも、最前面のウィンドウにおいて結果が選択されたままになるのですが、続けてテキストを入力していくのにその状態では都合が悪い場合もあるわけです。…サンプルに、処理後にキャレットを移動するものがありました。

--
property newStr : "TEMPLATE"
--
--
tell application "CotEditor"
    if exists front document then
        set {loc, len} to range of selection of front document
        set numOfMove to count of character of newStr
        set contents of selection of front document to newStr
        set range of selection of front document to {loc + numOfMove, 0}
    end if
end tell

サンプルを元に書いたものを次に挙げます。元ネタはどっかから拾ってきた、Internet Timeを出力するスクリプトです。どこで改行するか、どのようにエスケープするか、どのようにクォートするかとかで悩みました。それにしても、AppleScriptの文法は苦手です…

tell application "CotEditor"
    if exists front document then
        set {loc, len} to range of selection of front document
        set (contents of selection of front document) to (do shell script "/usr/bin/perl -e 'if ($0 eq __FILE__) {
    print &Bdate.\"\\n\";
}

sub Bdate
{
    local($time)  =  @_;
    local($beat);
    $time = $time || time;
    local($sec, $min, $hour) = (gmtime($time+60*60*1))[0..2];
    $beat = ((($hour * 60 + $min) * 60 + $sec) / 86.4) % 1000;
    sprintf(\"@%03d\",$beat);
}
1;'")
        set numOfMove to count of character of selection
        set range of selection of front document to {Loc + numOfMove, 0}
    end if
end tell

大体において、やりたいことが出来そうなのが分りました。

Meta Infomation of this entry

You can add this Entry to your  はてなブックマーク and Delicious

Sun, 12 Jun 2005

CotEditor用のスクリプトを書いてみる

CotEditor用のスクリプトを書いてみた。といっても一から書いたわけではなく、KEdit用のスクリプトからの流用ですが。参考にしたのは、添付されている次のようなシェルスクリプトです。

#! /bin/sh
# %%%{CotEditorXInput=Selection}%%%
# %%%{CotEditorXOutput=ReplaceSelection}%%%

INPUT=`cat -`
echo "<h1>${INPUT}</h1>"

最初はどのようにしたら良いかピンとこなかったのですが、パイプしてやれば良いことに気付きまして、その後は順調に進みました。参考までに、いくつか例を挙げておきます。…使っているコマンドがsedやら何やらと古いのは、これらのスクリプトが古くはMacOS8くらい、HundoshiEditsedMacjgawkMacのために書いたものだから。(念の為に…これらはMacOSXの今も現役のソフトウェアです。)

#! /bin/sh
# %%%{CotEditorXInput=Selection}%%%
# %%%{CotEditorXOutput=ReplaceSelection}%%%

INPUT=`cat - | sed "
    s/&/\&amp;/g
    s/</\&lt;/g
    s/>/\&gt;/g
    s/\"/\&quot;/g"`
echo ${INPUT}
#! /bin/sh
# %%%{CotEditorXInput=Selection}%%%
# %%%{CotEditorXOutput=ReplaceSelection}%%%

INPUT=`cat - | awk '{
    if (/^$/)
        next
    else
        sub("^","\t<li>")
        sub("$","</li>")
    print
}'`
echo "<ul>
${INPUT}
</ul>"

あ、今回ハマった点をひとつ。スクリプトの二行目から三行目のコメント部分は必須なので、削除してはダメ。アプリケーションがクラッシュします。最初はスクリプトにエラーがあるせいだと思っていたのですが、そういう場合はCotEditorScript Error windowに表示されるのですね。

…どうしてこれを書こうとしたかというと、先行き不安だったから(何が)。

Meta Infomation of this entry

You can add this Entry to your  はてなブックマーク and Delicious

Wed, 08 Jun 2005

MacUIM0.4.1-1

MacUIM0.4.1-1が出ています。バグフィックス・リリース。

取りあえず、SafariPowerMailが落ちる不具合は解消されているようです。しかし、Safari等で、数秒間にわたってレインボーカーソルが回り、その間操作不能になる不具合は残ったままです。

Safari撃墜されまくり状態からは抜けたので、再びAquaSKKからMacUIMskkへ乗り換えすることにしました。入力モードが表示されないAquaSKKは不便だし。

開発者の方に感謝します。

Meta Infomation of this entry

You can add this Entry to your  はてなブックマーク and Delicious

Tue, 07 Jun 2005

インテル入ってるまっきんそのに

まー、iPod/iTunes等でお金がある(体力に余裕がある)今が決断の時だったのだな。クロックアップとかで先行き不安なPowerPCを捨てるという決断をしたのは…企業として、思い切った、でも多分良い決断だと思う。

個人的には、悩んでもしょうがない、というのはある。クラシック環境は切り捨てられちゃうけど、その他の資産を引き継げないというわけでもないし。機械の中にどのチップが入っていようが、関係無いし。というか、ハードウェアには関心が無いし。インテル入ってるまっきんになったって、多分ういんどうずが動くというようなことは無いだろうし、そういった意味では何も変らないと思う。ということで、この件については終了。

Meta Infomation of this entry

You can add this Entry to your  はてなブックマーク and Delicious

インテル入ってるまっきん

うーむ。林檎マークの下とかにインテル入ってるシールが貼られたりすることになるのかもしれん。かっこわる。

個人的には、多分そこらにころがっているインテル入ってるマシンでMacOSXをというのはダメなんだろうと予測するんだけど、そこのところをはっきり言っていないそうなので、それは良くないなぁ、と。

後、来年発売されるというインテル入ってるまっきんでういんどうずが動くというのも考えにくいな…

Meta Infomation of this entry

You can add this Entry to your  はてなブックマーク and Delicious

<<  Page 8 of 35  >>

Le violon intérieur....
Yasuo Yamashita
vaiorinnhiATTOnaDOTrimDOTorjye-pi-
Y.A.S.U.O Ytterbium Artificial Sabotage and Utility Organism Y.A.S.U.O Yelling Abomination from the Sunless Underground Oasis

Pyblosxom and plugins. For detail, see http://viole.sakura.ne.jp/blosxom/blosxom.cgi/plugin_info