Very simple terminal / applescript / textmate problem

Discussion in 'Mac Programming' started by majorp, Nov 29, 2007.

  1. macrumors 6502

    Joined:
    Nov 28, 2005
    Location:
    UK !!!
    #1
    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

    Code:
    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
     
  2. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Perhaps try

    Code:
    do script "cd '$TM_DIRECTORY'; javac '${TM_FILENAME%}'; java '${TM_FILENAME%.java}'"
    ?
     
  3. macrumors 601

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #3
    Just 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
     
  4. thread starter macrumors 6502

    Joined:
    Nov 28, 2005
    Location:
    UK !!!
    #4
    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?
     
  5. macrumors 601

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #5
    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.
     
  6. thread starter macrumors 6502

    Joined:
    Nov 28, 2005
    Location:
    UK !!!
    #6
    Perfect!

    Thanks guys/gals for your time :)
     

Share This Page