最近、Firefoxをお休みしてSafari4.0.2を試してみている。
→Safari4.0.2が良さそうなのでしばらく使う (うむらうす)
確かに、サイトを開きまくってもメモリが増えて行きにくい感じがする。
そして速い。今のところほぼ満足。
しかしちょっと不便なところがある。
Firefoxのアドオン代替が完全ではないからだ。
例えば、MakeLink。
これはURL+と並んでブロガーには必須なわけだが、Safariにはない。
探したところ、すばらしいAppleScriptが紹介されているのを発見した。
→SafariでMake LinkするAppleScript | r.izumitaの航跡
これは良い!
ただ、私の使い方と少しとズレていたので微調整させてもらった。
具体的には、以下の通り。
	- 文字列を選択していないときはaタグ、しているときはblockquoteタグが
作られるのだが、どちらもaタグで統一した 
	- blockquote用スクリプトは別に準備
 
aタグ用、blockquoteタグ用それぞれのスクリプトを、
「アプリケーションバンドル」形式で保存(「初期画面」のチェックは外す)
すればアプリケーションっぽく使える。
butlerでSafariでのみ有効なホットキーを登録すれば、
あたかもSafari用プラグインみたい。超便利。
ということで載せておく。
aタグ作成スクリプト
変更点は以下の4点。
	- 文字化け除けのおまじないとして、theURLとtheTitleをUnicode textとして保存
 
	- タグに含まれるシングルクォート「'」をダブルクォートに。「'」 → 「\"」
 
	- 文字列が選択されていた場合も、blockquoteではなくaタグに
 
	- titleプロパティーを追加
 
1)スクリプトメニュー用
ファイルはこちら→MakeLink_for_Safari(a).app.zip
ダブルクリックで解凍できるはず。
ファイル名は適当に変えて使ってください。
ソースは以下。
tell application "Safari" 
set theURL to URL of document 1 as Unicode text
set theTitle to name of document 1 as Unicode text
set theSelection to do JavaScript "unescape(escape(getSelection()));" in document 1
end tell
if theSelection is "" then
set theText to "<a href=\"" & theURL & "\" title=\"" & theTitle & "\">" & theTitle & "</a>"
else
set theText to "<a href=\"" & theURL & "\" title=\"" & theTitle & "\">" & theSelection & "</a>"
end if
set the clipboard to theText as Unicode text
 
2)ユニバーサルパレット用
ファイルはこちら→MakeLink_for_Safari(a).scpt
ユニバーサルパレットでは、アプリケーションバンドル形式に
しなくても動いたので、scptファイルのまま。
ソースは以下。
on convert_lines(theLines)
tell application "Safari" 
set theURL to URL of document 1 as Unicode text
set theTitle to name of document 1 as Unicode text
set theSelection to do JavaScript "unescape(escape(getSelection()));" in document 1
end tell
if theSelection is "" then
set theText to "<a href=\"" & theURL & "\" title=\"" & theTitle & "\">" & theTitle & "</a>"
else
set theText to "<a href=\"" & theURL & "\" title=\"" & theTitle & "\">" & theSelection & "</a>"
end if
set the clipboard to theText as Unicode text
set the clipboard to theResult
end convert_lines
 
blockquoteタグ作成スクリプト
 
変更点は以下の通り。
	- titleタグ除去
 
	- シングルクォート→ダブルクォートに「'」→「"」
 
	- <p>→<div>
 
1)スクリプトメニュー用
ファイルはこちら→MakeLink_for_Safari(bq).app.zip
ダブルクリックで解凍できるはず。ファイル名は適当に変えて使ってください。
ソースは以下。
tell application "Safari"
set theURL to URL of document 1 as Unicode text
set theTitle to name of document 1 as Unicode text
set theSelection to do JavaScript "unescape(escape(getSelection()));" in document 1
end tell
 
if theSelection is "" then
set theText to "<blockquote cite=\"" & theURL & "\">" & return & "<div>" & return & "<cite><a href=\"" & theURL & "\">" & theTitle & "</a></cite></div>" & return & "</blockquote>" & return
else
set theText to "<blockquote cite=\"" & theURL & "\">" & return & "<div>" & return & theSelection & "<cite><a href=\"" & theURL & "\">" & theTitle & "</a></cite></div>" & return & "</blockquote>" & return
end if
set the clipboard to theText as Unicode text
 
2)ユニバーサルパレット用
ファイルはこちら→MakeLink_for_Safari(bq).scpt
ユニバーサルパレットでは、アプリケーションバンドル形式に
しなくても動いたので、scptファイルのまま。
ソースは以下。
on convert_lines(theLines)
tell application "Safari"
set theURL to URL of document 1 as Unicode text
set theTitle to name of document 1 as Unicode text
set theSelection to do JavaScript "unescape(escape(getSelection()));" in document 1
end tell
 
if theSelection is "" then
set theText to "<blockquote cite=\"" & theURL & "\">" & return & "<div>" & return & "<cite><a href=\"" & theURL & "\">" & theTitle & "</a></cite></div>" & return & "</blockquote>" & return
else
set theText to "<blockquote cite=\"" & theURL & "\">" & return & "<div>" & return & theSelection & "<cite><a href=\"" & theURL & "\">" & theTitle & "</a></cite></div>" & return & "</blockquote>" & return
end if
set the clipboard to theText as Unicode text
set the clipboard to theResult
end convert_lines
 
これらを、Butlerでショートカットを登録するわけです。
こんな感じ。
これで、あたかもSafariでだけ発動するプラグインみたい。Good!
まとめ:
	- MakeLinkっぽいAppleScriptを作った(aタグ、blockquoteタグ用)
 
	- 呼び出しはスクリプトメニューからかユニバーサルパレットから
 
	- ショートカットを登録するとプラグインっぽくなる
 
良い感じだ。