1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CotEditorスクリプトで編集中のファイルに対してgnuplotを実行する。

Posted at

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アプリを登録しておくとよい(いろいろなサンプルがネットで公開されてる)。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?