まずは前準備として、「How to create a TinyURL with LB (incl. paste to clipboard)」を参考に2つのスクリプトファイルを作成します。
1つはPythonスクリプト:
#!/usr/bin/python from urllib import quote from sys import argv if argv[1]: print quote(argv[1],'/:')
適当なテキストエディタで、上記ソースを書き入れたドキュメントを作成します。名称を「escapeurl」とし、文字コードはUTF-8で.txt拡張子は付けないようにします。~/bin/escapeurl へ実行権限を付けて保存します。
2つ目はAppleScript:
-- based on http://www.leancrew.com/all-this/2007/11/long-and-shortened-url-scripts/ -- & http://www.leancrew.com/all-this/2009/02/url-shortening-scripts-fixed-i-think/ -- by @drdrang -- modified by @ptujec (for LaunchBar) on handle_string(longURL) set safeURL to do shell script "~/bin/escapeurl " & "'" & longURL & "'" set cmd to "curl 'http://is.gd/api.php?longurl=" & safeURL & "'" set shortURL to do shell script cmd set the clipboard to shortURL as text end handle_string
上記ソースをスクリプトエディタで作成して、~/Library/Application Support/LaunchBar/Actions/tinyURL.scpt へ保存します。
LaunchBarのインデックスを再構築して終了です。
使い方は、URLをコピーしてLaunchBarでtinyURLスクリプトを呼び出しスペースバーを押し下げテキストフィールドへURLをペーストしリターンキーを押し下げます。これでクリップボードへ短縮URLが格納されます。
