|
|
#1 |
|
Prospect
Join Date: Apr 2012
Posts: 4
|
Help Typing in Terminal.app
I am building an applescript that edits a macs hosts file. Below is what i have so far. But the part in red and underlined is not working, I Cant get it to type the earlier entered password to enter in terminal when the sudo command asks for a password.
-------Begin Script------- set example to "Installation Has Been Canceled" display alert "This installation will block communications between the adobe servers and all your Adobe Products CS5.5 and earlier. This should not be used to pirate Adobe Products. User assumes all blame for any leagal repercussions. To continue, please press OK. Otherwise, Press Cancel." buttons {"Cancel Installation", "I Agree"} set theAnswer to button returned of the result if theAnswer is "I Agree" then tell application "Terminal" do script " sudo nano /private/etc/hosts" end tell display alert "Terminal will need an administrator password to complete the instalation. Would you still like to continue?" buttons {"Cancel Installation", "OK"} display dialog "Type your password below, and click OK." default answer "" set thepassword to text returned of the result tell application "Terminal" do script keystroke thepassword end tell else do shell script "/usr/bin/say " & quoted form of example & " &> /dev/null &" display alert example end if ------End Script------ |
|
|
|
|
|
#2 |
|
League Commissioner
Join Date: Jan 2002
Posts: 7,996
|
You won't see your password as you type it in the terminal.
How do you know that the password is not being entered? Do you get an error as a result? |
|
|
|
|
|
#3 | |||||||||||||||||||||||
|
League Commissioner
Join Date: Sep 2003
Location: Tokyo
Posts: 6,057
|
You don't script nano - it's an interactive editor. It appears that all you want to do is add one line to /etc/hosts. You do this with the append function. And you never bother with flinging around the user's (or admin's) password - let the OS handle it. Code:
do shell script "echo '127.0.0.1 adobe.com' >> /private/etc/hosts" with administrator privileges |
|||||||||||||||||||||||
|
|
|
|
|
#4 |
|
Prospect
Join Date: Apr 2012
Posts: 4
|
Yes, there was an error saying it cant keystroke the variable "thePassword"
Thanks for the help guys. Do you know of any good resources to learn applescript? Last edited by MacHacker24; 05-06-2012 at 09:21 AM. |
|
|
|
|
|
#5 |
|
Hall of Famer
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 4,948
|
The error is that do script expects a string. Your line should read:
do script "keystroke " & thepassword but the other comments apply -- let the system look after that.
__________________
17" MBP, OS X 10.8.3; 27" iMac, OS X 10.8.3 |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|