Path Finderから、svn diff

前回のつづき。

前回同様、スクリプトエディタの新規書類に以下のソースをコピペして、「アプリケーション」として保存する。

property svn : "/usr/local/bin/svn"
property svnopt : "diff"
property nkf : "/usr/local/bin/nkf -s"

on run
  open ({choose file})
end run

on open (DirectoryList)
  repeat with theDirectory in DirectoryList
    try
      set thePath to POSIX path of theDirectory
      set theCommandLine to (svn & " " & svnopt & " '" & thePath & "' | " & nkf)
      set theResult to (do shell script theCommandLine)
      if (theResult /= "") then
        set theTitle to (svnopt & " '" & thePath & "'")
        displayResult(theTitle, theResult)
      end if
    on error theErrorMessage
      displayOKDialog("Error:" & return & theErrorMessage)
    end try
  end repeat
end open

on displayResult(theTitle, theResult)
  set the clipboard to theResult
  tell application "Jedit X"
    make new document
    tell front document
      activate
      set name to theTitle
      do menu item "ペースト"
      set modified to false
    end tell
  end tell
end displayResult

on displayOKDialog(theMessage)
  display dialog theMessage buttons {"OK"} default button 1
end displayOKDialog

処理内容について簡単に補足しておくと、AppleScriptに於いて、文字列は原則的にShiftJISで取り回す点に注目。(何故か、OS標準のUTF-8ではないのです)
文字コード変換はTEC OSAXとかで行うのがよりAppleScriptらしい実装と思うけど、動いてナンボということもあって、外部のOSAXには依存しない方向でnkfで済ませた。(その意味で厳密にいえば、OSに含まれないnkfではなくiconvコマンドを使うべきだろうけど、なんか使いづらいし)
最後に、svnコマンドの出力をJedit Xの新規テキストにコピペして、処理終了。

このソースから作ったDropletを、LaunchItemsと併用してコンテクストメニュー(右クリックメニューと言ったほうが分かりやすいか)に登録すると便利。
本来ならFinderPopFruitMenuを使いたいところだが、PathFinderのコンテクストメニューに登録されるのはLaunchItetmsだけ。
そもそもPathFinderのコンテクストメニューに、任意のアプリを登録する機能があったら良かったんだけど。

あまり時間もないので、このあたりで一旦Fixとしておく。

トラックバック

コメント


コメントはすぐには反映しません。
ほぼ毎日チェックしていますが、翌日以降の反映となることもあります。

Twitter