選択したFinder項目の差分をサービスメニューから取りたい!

・Finderで選択したテキストファイルの差分を取りたい!
・FileMerge*1DiffMergeドラッグアンドドロップに対応してない!
・でもFileMergeはコマンドラインから使えるらしい!
・_人人人人人人人人_
 > 突然のAutomator <
  ̄^Y^Y^Y^Y^Y^ ̄

・Automatorを起動します。
・「AppleScript を実行」を右ペインにドラッグします。
・"サービス"は、次の選択項目を受け取ります:書類
・検索対象:Finder
・以下のAppleScriptを貼り付けます。

on run {input, parameters}
	tell application "Finder"
		set FileList to selection as alias list
	end tell
	if length of FileList = 2 then
		set name1 to (the quoted form of the POSIX path of item 1 of FileList)
		set name2 to (the quoted form of the POSIX path of item 2 of FileList)
		set result1 to do shell script "file --mime-type " & name1
		set result2 to do shell script "file --mime-type " & name2
		if result1 contains "text" and result2 contains "text" then
			do shell script "opendiff " & name1 & " " & name2 & " > /dev/null 2>&1 &"
		else
			display dialog "one (or both) is not text file."
		end if
	else
		set cnt to length of FileList
		display dialog "Select 2 text files:" & cnt
	end if
	#return input
end run

・Finderからの選択項目の取得は「選択された Finder 項目を取得」というAutomatorのアクションでもできるんだけど、なぜかこれで選択すると
2こファイル選択してるはずなのに4つのパラメータが飛んでくるときがあり、謎な挙動だったため直接AppleScriptで取得してます。
・サービスを別名で保存します。今回は「Compare with FileMerge」という名前で保存しました。

・ついでにショートカットも割り当てると便利ですね!

・ほんで右クリック

・ほんでdiff!

・ヤッター!

参考:わかばマークのMacの備忘録 : Automator で Service を作成

*1:FileMergeはXcodeをインストールするとついてきます