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

zredbaron

macrumors newbie
Original poster
Apr 9, 2008
3
0
does anyone know how i can create an alias programattically from java?

i've done google searches and found commands to type into a terminal, but they are limited in that they dont seem to allow an icon file.

to complicate things, i don't believe Runtime.getRuntime().exec(String[] args); handles commands like the terminal does.

is there a way to enter commands into a terminal from java?

thanks in advance.
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
If trying to invoke the commands directly isn't working, you might want to make a very short shell script that does this, and invoke that from your program.

-Lee
 

zredbaron

macrumors newbie
Original poster
Apr 9, 2008
3
0
ah, that sounds like a very good idea!

but how exactly would i go about calling a shell script from java? i tried asking google, but i dont seem to be typing in the right search string....
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
catch-22, I suppose. You're back to using exec. It should be ok if the script is in your path. A much messier way is to use JNI to get into C/C++, but that is the road to madness.

Are you using java to do some system scripting? Or is this the OS X installer of a larger Java app? If you're just trying to automate things, java may not be the way to go.

-Lee
 

zredbaron

macrumors newbie
Original poster
Apr 9, 2008
3
0
found a solution for the script part:

String[] test = {"sh", ".script.sh"};
runtime.exec(test);

thanks a lot for the idea.

i think ill post the bit about the alias in a new thread. thanks again.
 

jeremy.king

macrumors 603
Jul 23, 2002
5,479
1
Holly Springs, NC
Since you are simply calling a script from Java, you may want to consider calling an Applescript instead.

Your input arguments to exec() would be
Code:
String[] test = {"osascript", "YourAppleScript.scpt"};
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.