ブログの整理

2014/06/17

ブログの見た目を変えてみたのだけど、色々とチェックしている際に気になったのが記事内にある(主に AppleScript の)ソースコード。

見にくいですよね。

もう少し見やすくならないものかと色々と探してみました。

コードの整形やカラーリングを行うには SyntaxHighlighter なるものが主流のようですね。

なんだけど、いまいちピンとこない。

他にないかなと思いつつ探していたら、Gist のコードをそのまま貼付けることができるらしい。試しに貼ってみる。

tell application id "com.apple.finder"
set workingFolder to insertion location
try
set parentFolder to (container of workingFolder) as alias
on error msg number num
if num is -1728 then
error msg
else
error msg number num
end if
end try
set currentSelection to selection
if currentSelection is {} then return
set targetClasses to {}
repeat with thisItem in currentSelection
if (class of thisItem) is document file then
if name extension of thisItem is not in targetClasses then set end of targetClasses to name extension of thisItem
else if (class of thisItem) is folder then
if folders is not in targetClasses then set end of targetClasses to folders of workingFolder
else
--
end if
end repeat
--return targetClasses
set theseItems to {}
repeat with thisClass in targetClasses
set thisClass to contents of thisClass
if (class of thisClass) is text then
set theseItems to theseItems & (files of workingFolder whose name extension is thisClass)
else
set theseItems to theseItems & thisClass
end if
end repeat
theseItems
ignoring application responses
set selection to {}
set selection to theseItems
end ignoring
end tell

見やすいと思うのですが、どうでしょう?

導入も簡単だし、AppleScript Editor から直接 Gist に投稿、ソースコードのリンクを作成し取得するという一連の流れがすべて AppleScript で制御できる。

問題はそれなりのスクリプトならともかく、断片のようなスクリプトをどうするかって事だけど。

とりあえずは Gist との連携でいってみようか...。