Hello to all you lovely scripterperople out there. I’ve been trying to make an applescript that will
prompt the user for a username and password and doing a do script “su “& user_name &””
before entering some_password at the prompt. I’d like to do this so i can write a script that can be
used by non-admin users to do a particular terminal comand. The reason i cant just do shell script
and sudo with administrator privilages is that one of the comands i want to use is /sbin/shutdown
-h +some_number and sleep comands, which cause AppleScript to stay open until the command is
complete. How do i get applescript to do a command in the terminal, enter the password and press
This is what i have so far. It seems to work but for a reason unknown to me it causes the Terminal to quit.
set myUser to text returned of (display dialog "Please enter your login Username. Leave this field blank to log in as root user." default answer "") if the text of myUser is "" then set myUser to "root" end set myPass to text returned of (display dialog "Please enter your login password for user \"" & myUser & "\"." default answer "" with hidden answer) if the text of myUser is "root" then set myUser to "" end tell application "Terminal" launch delay 1 do script "echo " & myPass & " | su " & myUser & "" in window 1 quit do script "whateveryouwanttodo" in window 1 end tell
Any help in this would be awesom!