|
|
#1 |
|
Prospect
Join Date: Apr 2012
Posts: 4
|
I am making an Applescript to edit the host file on a mac. This is all I have so far, but when I click compile, I get an error: "The variable button_pressed is not defined." Can anyone help me out?
AppleScript: tell application "Finder" display dialog "This application will block Homecalling in Adobe Products CS5.5 and Earlier. To continue, please press OK. Otherwise, Press Cancel." end tell if button_pressed = "OK" then tell application "Terminal" do script " sudo nano /private/etc/hosts" end tell end if if button_pressed = "Cancel" then tell application "Finder" display dialog "You Have Canceled The Installation" end tell end if |
|
|
|
|
|
#2 |
|
Major Leaguer
Join Date: Apr 2010
Posts: 324
|
If you just run:
Code:
tell application "Finder" display dialog "This application will block Homecalling in Adobe Products CS5.5 and Earlier. To continue, please press OK. Otherwise, Press Cancel." end tell Code:
{button returned:"OK"}
The correct phrasing for what you want is: Code:
button returned of result Code:
if button returned of result = "OK" then Code:
error "Finder got an error: User canceled." number -128
__________________
see a problem; solve a problem. |
|
|
|
|
|
#3 |
|
Prospect
Join Date: Apr 2012
Posts: 4
|
Thanks you, I am new to applescript and have lots to learn!
|
|
|
|
|
|
#4 |
|
MVP
Join Date: Apr 2008
Location: Berkeley CA USA
Posts: 1,009
|
Another way to get the script to continue even if the user presses "Cancel" is to spell it differently, as in:
Code:
tell application "Finder"
display dialog "This application will block Homecalling in Adobe Products CS5.5 and Earlier. To continue, please press OK. Otherwise, Press Cancel." buttons {"OK", " Cancel "}
end tell
if button returned of the result = "OK" then
tell application "Terminal"
do script " sudo nano /private/etc/hosts"
end tell
else
-- user pressed " Cancel "
tell application "Finder"
display dialog "You Have Canceled The Installation" buttons {"OK"} default button 1
end tell
end if
Notice the buttons {"OK"} default button 1 in the second display dialog, so the user can dismiss the dialog by simply pressing return or enter, rather than having to use the mouse to click on one of the two buttons and wondering what the difference is between them. But you have other problems. The terminal command is only going to open /private/etc/hosts for editing in a new window. A user who doesn't already know what to do in that window (if they see it at all -- it may be hidden behind other windows) will be mystified what to do next; a user who does know what to do next isn't going to bother running an Apple Script to do something they already know how to do in Terminal. |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|