DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Compile The Front TextWrangler Java Source File Using Applescript

01.19.2006
| 4880 views |
  • submit to reddit
        // If you use TextWrangler to edit java source code,
// this AppleScript will compile the front window.

tell application "TextWrangler"
	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)

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

tell application "Terminal"
	activate
	set shell_script to "cd " & (quoted form of POSIX path of the_folder) & "; javac " & source_file
	if (count windows) is 0 then
		do script shell_script
	else
		do script shell_script in the front window
	end if
end tell
    

Comments

Snippets Manager replied on Sat, 2010/01/30 - 4:11am

I just wanted to say thanks for posting this code. I am taking a Java class in college and this is very useful to me. I added to it just enough to make it run the code automatically. tell application "TextWrangler" 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) tell application "Finder" set the_folder to container of the_file as alias end tell set AppleScript's text item delimiters to "." set byte_code to the first text item of source_file tell application "Terminal" activate set shell_script to "cd " & (quoted form of POSIX path of the_folder) & "; javac " & source_file & " && clear && java " & byte_code if (count windows) is 0 then do script shell_script else do script shell_script in the front window end if end tell The set byte_code line and the shell script have been modified. One placed in my scripts folder I launch it whenever I like using Quicksilver. It's made my whole day easier. Thanks again, Bill