I'm designing a little software in Java. I 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 gksudo
for commands that required the root password.
Is there any gksudo
in OS X? Any graphical popup asking for root password?
make the follows, in this example I go create a folder /var/lock and set your permissions to 777:
on linux maybe you can make this with gksudo but I not test it, after I go testing and post here the results.
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.
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 togksudo
which I believe uses a graphical popup). Sudo works on both Linux and OS X.Following ZJR's answer, I've made this into automator, so you can use it as a Service or whatever:
Or, maybe you just think his answer is outdated and still want an AppleScript, just write this single line in Script Editor:
Which you can then make into an app and use it as a Service or whatever.
This also looks promising:
cocoasudo
It uses the OSX native Authorization Services API:
One should use the native OS X authorization services instead of looking at sudo and/or a graphical interface to it.
Ref:
Introduction to Authorization Services Programming Guide (apple)
Authorization Services Tasks (apple)
[I know it's a late answer ...]