views:

577

answers:

5

Hi. I'm designing a little software in java. Don't know the term/definition to what I'm doing, but I'm prompting commands from java to the terminal. Something like this:

Process process = Runtime.getRuntime().exec("command");

I've done this before in linux, and I used the gksudo for commands that required root password.

Is there any "gksudo" in os x? Any graphical popup asking for root password.

Thanks =)

A: 

If you are using a terminal, then just use "sudo" instead, which will prompt for the user's password in the terminal itself (as opposed to gksudo which I believe uses a graphical popup). Sudo works on both Linux and OS X.

Adam Batkin
it's supposed to be graphical ... =)
Johannes
+1  A: 

gksudo is the GTK+ version of sudo.

You can use this clone for it especially for OS X.

LiraNuna
A: 

This also looks promising:

http://www.performantdesign.com/2009/10/26/cocoasudo-a-graphical-cocoa-based-alternative-to-sudo/

It uses the OSX native Authorization Services API.

tam7t
+1  A: 

you can more ore less manage to write your own with Applescript

#!/bin/sh
asascript -e "do shell script \"$*\" with administrator privileges"

cocoasudo looks nicer, though. But this is already deployed.

ZJR
+1  A: 

I found the cocoasudo doesn't work if you are running a shell script that calls other commands. You would have to use cocoasudo in all sub-commands also which would pop up a prompt for each call.

The osascript solution seems to work better, but I needed to tweak it to work with commands involving paths containing spaces.

#!/bin/sh
export bar=""
for i in "$@"; do export bar="$bar '${i}'";done
osascript -e "do shell script \"$bar\" with administrator privileges"
shannah