Good morning,
As it’s morning here in my part of the world, I write this, so please excuse any confusion.
Unless I have not had my coffee, then I seem to be having some problems writing a simple yes or no dialog. Well, not exactly trouble, but more like I’m stumped.
I wrote the yes and no dialog, and while they work, when a person clicks on either my, Visit Application website, file bug report, or quit buttons after the no dialog, a peace of my ping result is displayed. Host unreachable, yet the action the user requested is performed.
Here’s the code. I suppose that’s what I get for not having coffee? Maybe?
Anyway, here it is.
#Ping Start
set question to display dialog "Do you wish to ping an IP Address now?" buttons {"Yes", "No"} default button 2
set answer to button returned of question
if answer is equal to "Yes" then
set IP_address to ""
set dialog_1 to display dialog "Enter IP Address:" default answer "" with title "Ping IP Address"
set the IP_address to the text returned of dialog_1
end if
if answer is equal to "No" then
display alert "Thank you for using this application. If you liked using this application, please consider donating by visiting the application website and clicking on donate. Any amount donated would be greatly appreciated.
Would you like to file a bug report? Visit the main application website?Or quit?" buttons {"FileBugReport", "VisitApplicationWebSite", "Quit"}
set the button_pressed to the button returned of the result
#Buttons
set VisitApplicationWebSite to "http://firestar-hosting.com/mac"
set FileBugReport to "http://firestar-hosting.com/mac/bugs"
if the button_pressed is "VisitApplicationWebSite" then
open location VisitApplicationWebSite
else
if the button_pressed is "FileBugReport" then
open location FileBugReport
else
if the button_pressed is "Quit" then
error number -128
end if
end if
end if
end if
try
do shell script ("ping -c 2 " & IP_address)
display dialog "Host up" buttons {"OK"} default button 1 with title "Host Status"
on error
display dialog "Host unreachable" buttons {"OK"} default button 1 with title "Host Status"
end try
Again, someone can click on the no button, and all works well. The last dialog comes up telling them thanks for using the app, and giving them the 3 buttons; file bug report, visit the app website, or quit. If they click on 2 out of the 3 buttons, Safari launches, but the user also gets a notification that, host is unreachable, even though they selected the no option and have clicked on a button that’s part of another dialog all together.
Again, thanks for any help to sort this out. It’d be a good time for coffee now I believe.