How do I grab input from the user in AppleScript and then pass the result of the variable to a do shell script
command from within AppleScript itself?
For example, the user would type the answer foo
to the following dialog box:
display dialog "Please enter your username" default answer ""
set the userID to the text returned of the result
do shell script "rm -rf /Users/$userID/.Trash/*" with administrator privileges
So in this instance, if I were to incorporate the answer of foo
in lieu of $userID
, it would read as the following when it executes the command:
display dialog "Please enter your username" default answer ""
set the userID to the text returned of the result
do shell script "rm -rf /Users/foo/.Trash/*" with administrator privileges
How do I pass that variable I grabbed earlier, in this case it would be $userID and incorporate it into the middle of the shell script
call that I have made just above.
Best Answer
This assigns the name entered to the variable
answer
.