Most of you folks on this list are probably way too geeky to find this
interesting, but I occasionally run across comments in blogs or on
mailing lists to the effect that this or that command line tool would
be handy to have in the GUI environment, so maybe it'll be useful for
some. Personally I rarely run Terminal, but from time to time I want to
dash off a quick one-line shell command. To do so I trigger the
following AppleScript from a keyboard command defined in iKey (lots of
similar utilities should work just as well):
set frontApp to the name of (info for (path to frontmost application))
tell application frontApp to set userResponse to (display dialog "Enter
shell command:" default answer "" buttons {"Cancel", "sudo", "OK"}
default button "OK")
set userCommand to text returned of userResponse
if button returned of userResponse is "sudo" then
do shell script ("sudo " & userCommand) with administrator privileges
set commandResult to the result as string
else
do shell script userCommand
set commandResult to the result as string
end if
if commandResult is not "" then
tell application frontApp
display dialog commandResult buttons {"Copy", "OK"} default button
"OK"
if button returned of the result is "Copy" then set the clipboard to
commandResult
end tell
end if
The script pops up a dialog box with a text field where you can enter
your command. Hitting Return or clicking OK runs the command directly;
clicking the sudo button prepends sudo to your command and asks for
your password. If your command returns text, it is displayed in another
dialog and you have the option of copying it to your clipboard.
Don't use it to run a command that stays open, such as top.
I hope someone finds it useful.
Michael
--
<http://globalocal.blogspot.com/>
"Open the pod bay doors, Hal."
"I'm sorry, Dave. I'm afraid I can't do that."