[CODE] MacOS X code to execute shell command with administrator priviledges

Andre Garzia andre at andregarzia.com
Wed Jun 30 10:16:27 EDT 2010


Folks,

I just created a tiny function that I think might be useful for people here.

Sometimes you want to execute a command with shell() on mac os x but your
command needs to be run with administrator priviledges. Some might try to
script sudo to do this or just give up because scripting sudo is not that
easy. Well, it turns out there's a simpler solution using applescript. So
here it is:

function executeWithPriviledges pCmd
   do format("do shell script \"%s\" with administrator privileges", pCmd)
as applescript
   return the result
end executeWithPriviledges

also available at http://wecode.org/paste/A9HF2D6

This function will execute the command passed to it with administrator
priviledges, it will display the standard mac os x dialog box for
authorization. It uses applescript that in taps into Mac OS X Authorization
Services API.

It think it is useful, specially for all those people running "apachectl
graceful" from inside rev (is it just me?)

Andre

-- 
http://www.andregarzia.com All We Do Is Code.



More information about the use-livecode mailing list