端末と直接対話せずに.javaファイル/アプリケーションをコンパイルおよび実行するプロセスを自動化できるAppleScriptをオンラインで見つけました。ターミナルでコンパイルして実行する方法は知っていますが、TextPad for Windows でできるように、BBEdit から直接コンパイルまたは実行する方がはるかに便利です。ファイルごとにプロジェクトを作成したくないので、これにはIDEを使用したくありません。これが私が見つけたスクリプトです:
-- BBE Java Compiler v0.1
--
-- IMPORTANT:
-- You need to change the Java version to the version you want to use!
-- This is defined in "term_compile" below,
-- and currently set to 1.6
--
-- nanotux.com
tell application "BBEdit"
set the_file to file of text document 1
end tell
set AppleScript's text item delimiters to ":"
set source_file to the last text item of (the_file as string)
set compiled_file to text 1 thru -6 of source_file
tell application "Finder"
set the_folder to container of the_file as alias
end tell
tell application "Terminal"
activate
-- clear the current terminal window
set term_clear to "clear "
-- cd to the folder containing your file
set term_cd to "cd " & (quoted form of POSIX path of the_folder)
-- compile the .java file with a choosen version of Java
set term_compile to "javac -source 1.7 " & source_file
-- ^^ change to your Java version!
tell application "Terminal"
if (count windows) is 0 then
do script term_cd
do script term_clear in the front window
do script term_compile in the front window
else
do script term_cd in the front window
do script term_clear in the front window
do script term_compile in the front window
end if
activate
end tell
end tell
Java のバージョンを 1.7 に変更しましたが、基本的にファイルのパスが正しくないというエラーが表示されます。参考までに、私が受け取ったエラーの実際の写真を次に示します。
いつものように、どんなアドバイスも大歓迎です。
ありがとう!
編集: これは、AppleScript エラー ログに表示されるものです。
エラー「ファイル \"Macintosh HD:Users: userwitheld :Documents:School:Fall 2013:CINS 136:S08:MyType.java\"の «class ctnr» をタイプ エイリアスにできません。" ファイル "Macintosh HD:Users: userwitheld :Documents:School:Fall 2013:CINS 136:S08:MyType.java"の «class ctnr» からエイリアスに番号 -1700