2013-10-15 106 views
0

我找到了一個AppleScript在線應用程序,它可以讓我自動化編譯和運行.java文件/應用程序的過程,而無需直接與終端交互。我知道如何編譯和運行終端,但它可以更方便地直接從BBEdit編譯或運行,就像在TextPad for Windows中一樣。我寧願不使用IDE,因爲我不想爲每個文件創建一個項目。下面是我找到的腳本:Applescript編譯BBEdit .java文件無法正確設置路徑

-- 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 error in BBEdit

與往常一樣,任何意見是非常讚賞。

謝謝!

編輯:這是我在AppleScript的錯誤日誌中獲得:

錯誤 「無法使文件\«類CTNR»的」 Macintosh HD:用戶:userwitheld:文件:學校:2013秋季:CINS 136:S08:MyType.java \「轉換爲類型別名。」從文件的«類CTNR»號-1700 「的Macintosh HD:用戶:userwitheld:文件:學校:2013秋季:CINS 136:S08:MyType.java」 別名

回答

3

變化* the_folder *設置塊此:

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

它需要引用the_file作爲文件來使其工作。