I found an AppleScript online that should allow me to automate the process of compiling and running .java files/applications without directly interacting with terminal. I know how to compile and run with terminal, but it would be far more convenient to compile or run directly from BBEdit like you can in TextPad for Windows. I'd rather not use an IDE for this as I don't want to create a project for every file. Here is the script I found:
-- 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
I changed the Java version to 1.7, but I'm getting an error that, I believe, is essentially saying that the path of the file isn't correct. For reference, here is an actual photo of the error I receive.
As always, any advice is much appreciated.
Thanks!
EDIT: This is what I get in the AppleScript error log:
error "Can’t make «class ctnr» of file \"Macintosh HD:Users:userwitheld:Documents:School:Fall 2013:CINS 136:S08:MyType.java\" into type alias." number -1700 from «class ctnr» of file "Macintosh HD:Users:userwitheld:Documents:School:Fall 2013:CINS 136:S08:MyType.java" to alias
Change *the_folder* setting block to this:
tell application "Finder"
set the_folder to container of file the_file as alias
end tell
It needed to reference the_file as a file to get it to work.