Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jimmyfoveo

macrumors newbie
Original poster
Jan 9, 2009
1
0
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]);
		}
	}
}
 
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)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.