PDA

View Full Version : Very simple terminal / applescript / textmate problem




majorp
Nov 29, 2007, 07:13 PM
I have textmate and want the java "on run and compile" script to open terminal and compile and run the code.

this is what i have


osascript <<EOF
tell application "Terminal"
activate
try
close windows
end try
do script "cd '$TM_DIRECTORY'; javac '${TM_FILENAME%}'"
do script "cd '$TM_DIRECTORY'; java '${TM_FILENAME%.java}'"
end tell
EOF


works fine however it opens two terminal windows.

i don't know applescript and am just learning java.

how do I make both of the "do script" run in the same window?!

thanks



dejo
Nov 29, 2007, 07:25 PM
Perhaps try

do script "cd '$TM_DIRECTORY'; javac '${TM_FILENAME%}'; java '${TM_FILENAME%.java}'"

?

HiRez
Nov 29, 2007, 07:34 PM
how do I make both of the "do script" run in the same window?!

thanksJust combine them with a semicolon, since they need to be run in sequence anyway.

do script "cd '$TM_DIRECTORY'; javac '${TM_FILENAME%}'; java '${TM_FILENAME%.java}'"

EDIT: oops, beat me to it :P

majorp
Nov 29, 2007, 07:47 PM
Perhaps try

do script "cd '$TM_DIRECTORY'; javac '${TM_FILENAME%}'; java '${TM_FILENAME%.java}'"

?

worked wonderfully! but now I have another unforeseen problem.

when there is an error in the java code terminal throws an error but still runs the compiled java program from the previous compile making it confusing to whether you have a problem or not.

I need some sort of "on error pause" type of command although i'm not sure if this exists?

HiRez
Nov 29, 2007, 07:52 PM
worked wonderfully! but now I have another unforeseen problem.

when there is an error in the java code terminal throws an error but still runs the compiled java program from the previous compile making it confusing to whether you have a problem or not.

I need some sort of "on error pause" type of command although i'm not sure if this exists?Try using &&. I think that's supposed to continue only if the prior command succeeds:

do script "cd '$TM_DIRECTORY'; javac '${TM_FILENAME%}' && java '${TM_FILENAME%.java}'"

You may need a more sophisticated script though. Maybe it cleans up the intermittent files and reports the error or something.

majorp
Nov 29, 2007, 08:03 PM
Try using &&. I think that's supposed to continue only if the prior command succeeds:

do script "cd '$TM_DIRECTORY'; javac '${TM_FILENAME%}' && java '${TM_FILENAME%.java}'"

You may need a more sophisticated script though. Maybe it cleans up the intermittent files and reports the error or something.

Perfect!

Thanks guys/gals for your time :)