0

我在网上找到了一个 AppleScript,它应该允许我在不直接与终端交互的情况下自动编译和运行 .java 文件/应用程序的过程。我知道如何使用终端编译和运行,但是直接从 BBEdit 编译或运行会更方便,就像在 Windows 的 TextPad 中一样。我不想为此使用 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,但我遇到了一个错误,我相信它本质上是在说文件的路径不正确。作为参考,这是我收到的错误的实际照片。

BBEdit 中的 AppleScript 错误

与往常一样,非常感谢任何建议。

谢谢!

编辑:这是我在 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到别名

4

1 回答 1

3

将 *the_folder* 设置块更改为:

tell application "Finder"
    set the_folder to container of file the_file as alias
end tell

它需要将 the_file 引用为文件才能使其工作。

于 2013-10-16T00:49:53.987 回答