I develop a lot on OSX and there are times I need to run a GUI app as root, like a gui editor of a systems file, or running Wireshark. I could just run it from a terminal using "sudo", but that's not very cool. There is the Pseudo app, which is quite cool, and only $15, but I figured it wouldn't be too hard to script something together. Well, Many Hours Later, I've got something! An AppleScript droplet that can be added to your dock and when you drag another App on it, a GUI popup will ask for your password, and voila! You have a GUI app running as root.
Open Applications..Utilities..AppleScriptEditor, paste this below, and then save it as MSudo.app, as an Application. Then drag it onto your Dock
Open
on open {filename}
set p to POSIX path of filename
set myArray to my theSplit(p, "/")
set numItems to (count myArray) - 1
set AppNameFull to getArrayValue(myArray, numItems)
set myArray to my theSplit(AppNameFull, ".")
set numItems to (count myArray) - 1
set AppName to getArrayValue(myArray, 1)
do shell script p & "/Contents/MacOS/" & AppName with administrator privileges
end open
on theSplit(theString, theDelimiter)
-- save delimiters to restore old settings
set oldDelimiters to AppleScript's text item delimiters
-- set delimiters to delimiter to be used
set AppleScript's text item delimiters to theDelimiter
-- create the array
set theArray to every text item of theString
-- restore the old setting
set AppleScript's text item delimiters to oldDelimiters
-- return the result
return theArray
end theSplit
on getArrayValue(array, location)
-- very important -- The list index starts at 1 not 0
return item location in array
end getArrayValue
Update 2012/03/12: You can add a nice icon for this: http://stackoverflow.com/questions/8371790/how-to-set-icon-on-file-or-directory-using-cli-on-os-x http://icons.iconarchive.com/icons/iconshock/super-heros/128/superman-icon.png
No comments:
Post a Comment