Applescript run java with arguments

Discussion in 'Mac Programming' started by jimmyfoveo, Jan 9, 2009.

  1. jimmyfoveo macrumors newbie

    Joined:
    Jan 9, 2009
    #1
    Yesterday I was messing around with a little applescript. I tried running a java file using applescript and got that to successfully work. I then tried passing in a parameter using an applescript variable I couldn't get it to work. The code is below


    Applescript

    Code:
    property HelloVar : "Hello"
    do shell script "cd /Users/skylarwatson/desktop; java HelloWorld" HelloVar
    
    Java

    Code:
    public class HelloWorld { 
    	public static void main(String[] args) {
    		for(int i = 0; i < args.length; ++i) {
    			System.out.println(args[i]);
    		}
    	}
    }
    
     
  2. Sayer macrumors 6502a

    Sayer

    Joined:
    Jan 4, 2002
    Location:
    Austin, TX
    #2
    You have to concatenate (combine) the path and the variable:

    Code:
    property HelloVar : "Hello"
    do shell script ("cd /Users/skylarwatson/desktop; java HelloWorld " & HelloVar as string)
     

Share This Page