我发现AppleScript在线应该允许我自动化编译和运行.java文件/应用程序的过程,而无需直接与终端交互。我知道如何编译和运行终端,但是直接从BBEdit编译或运行会比在TextPad for Windows中更方便。我不想使用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错误日志中的内容:
错误“无法生成«class ctnr»文件\”Macintosh HD:用户: userwitheld :Documents:School:Fall 2013:CINS 136:S08:MyType.java \“into type别名“。编号-1700来自«class ctnr»文件“Macintosh HD:用户: userwitheld :Documents:School:Fall 2013:CINS 136:S08:MyType.java”to alias
答案 0 :(得分:3)
将* the_folder *设置块更改为:
tell application "Finder"
set the_folder to container of file the_file as alias
end tell
需要将the_file作为文件引用才能使其正常工作。