CotEditorのスクリプトで編集中のファイルに対してgnuplotを実行する方法。
CotEditorのScriptMenuフォルダに以下のファイルを保存する。
1)gnuplot.^@g.applescript
tell application "CotEditor"
if exists front document then
set file_path to path of front document as Unicode text
if (file_path is not "") then
set file_dir to (do shell script "/usr/bin/dirname " & file_path)
set cmd to "/bin/bash --login -c \"cd " & file_dir & ";" & "gnuplot " & file_path & "\""
set result to do shell script cmd
if (result is not "") then
display dialog result
end if
set cmd to "cat " & file_path & " | ruby -n -e 'print $_.scan(/^set output \"(.*)\"/)'"
set result to do shell script cmd
if (result is not "") then
set output_file_path to file_dir & "/" & result as POSIX file
display dialog "Done. Open " & output_file_path & "?" buttons {"Open", "Exit"} default button 1
set button_returned to button returned of result
if button_returned is "Open" then
tell application "Finder" to open file output_file_path
end if
else
display dialog "Done."
end if
else if (file_path is "") then
display dialog "Save the file before running."
end if
end if
end tell
以上。
ショートカットキー一発で実行できるので、gnuplotに限らずよく使うCUIアプリを登録しておくとよい(いろいろなサンプルがネットで公開されてる)。