• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Strange Errors
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Strange Errors


  • Subject: Re: Strange Errors
  • From: Yvan KOENIG <email@hidden>
  • Date: Mon, 10 Aug 2015 17:57:26 +0200


Le 10/08/2015 à 17:41, Daniel Chavez <email@hidden> a écrit :

Good morning/afternoon,
I’m trying to create a multi-dialog with the ability to ping an IP or domain name, or retrieve an IP.
I have an existing dialog as
display alert "What would you like to do" buttons {"RetrieveYourIP", "PingIPOrDomainName", "Quit"} cancel button "Quit" with title "Select a network option"
set the button_pressed to the button returned of the result
#Buttons
if the button_pressed is "RetrieveYourIP" then
say "Retrieving Your IP address, this may take a moment." without waiting until completion
WanIP()
display alert "Your IP Address is" & WanIP() & "And has been copied to your clipboard."
set the clipboard to WanIP()
on WanIP()
set WIP to missing value
set siteList to {"http://checkip.dyndns.org/", "http://whatismyip.com", "http://www.whatismyipaddress.com", "http://ipid.shat.net/", "http://www.edpsciences.comhtbin/ipaddress", "http://www.showmyip.com/"}
repeat with thissite in siteList
try
set WIP to item 1 of paragraphs of (do shell script "curl " & thissite & " | tr -cs '[0-9\\.]' '\\012' | awk -F'.' 'NF==4 && $1>0 && $1<256 && $2<256 && $3<256 && $4<256 && !/\\.\\./'")
if WIP is not missing value then exit repeat
end try
end repeat
return WIP
end WanIP
else
if the button_pressed is "PingIPOrDomainName" then
set IP_address to ""
set dialog_1 to display dialog "Enter IP Address:" default answer "" with title "Ping IP Address" buttons {"OK"} default button 1
set the IP_address to the text returned of dialog_1
try
do shell script ("ping -c 2 " & IP_address)
display dialog "Host is 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
endif
endif
endif
Expected “given”, “with”, “without”, other parameter name, etc. but found “””.
The entire code is
display alert "What would you like to do" buttons {"RetrieveYourIP", "PingIPOrDomainName", "Quit"} cancel button "Quit" with title "Select a network option"
set the button_pressed to the button returned of the result
#Buttons
if the button_pressed is "RetrieveYourIP" then
say "Retrieving Your IP address, this may take a moment." without waiting until completion
WanIP()
display alert "Your IP Address is" & WanIP() & "And has been copied to your clipboard."
set the clipboard to WanIP()
on WanIP()
set WIP to missing value
set siteList to {"http://checkip.dyndns.org/", "http://whatismyip.com", "http://www.whatismyipaddress.com", "http://ipid.shat.net/", "http://www.edpsciences.comhtbin/ipaddress", "http://www.showmyip.com/"}
repeat with thissite in siteList
try
set WIP to item 1 of paragraphs of (do shell script "curl " & thissite & " | tr -cs '[0-9\\.]' '\\012' | awk -F'.' 'NF==4 && $1>0 && $1<256 && $2<256 && $3<256 && $4<256 && !/\\.\\./'")
if WIP is not missing value then exit repeat
end try
end repeat
return WIP
end WanIP
else
if the button_pressed is "PingIPOrDomainName" then
set IP_address to ""
set dialog_1 to display dialog "Enter IP Address:" default answer "" with title "Ping IP Address" buttons {"OK"} default button 1
set the IP_address to the text returned of dialog_1
try
do shell script ("ping -c 2 " & IP_address)
display dialog "Host is 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
else
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"} cancel button "Quit"
set the button_pressed to the button returned of the result
#Buttons
if the button_pressed is "VisitApplicationWebSite" then
set VisitApplicationWebSite to "http://firestar-hosting.com/mac"
open location VisitApplicationWebSite
else
if the button_pressed is "FileBugReport" then
set FileBugReport to "http://firestar-hosting.com/mac/bugs"
open location FileBugReport
end if
end if
end if

Opening AppleScript dictionaries is often useful.
I don't know who told you to code :
display alert "What would you like to do" buttons {"RetrieveYourIP", "PingIPOrDomainName", "Quit"} cancel button "Quit" with title "Select a network option"
What I know is that it's a wrong syntax.

Opening Standard Additions dictionary would have tell you that you must use : 

display alert "What would you like to do" message "Select a network option" buttons {"RetrieveYourIP", "PingIPOrDomainName", "Quit"} cancel button "Quit"

I wish to add that when a script refuse to compile, the easier way to understand what is wrong is to try to compile instructions one by one.

Second point : inserting the handlers in the main code is - at least - bad practice.

I 'm not sure that I got what you wanted to get but here is a code which at least compiles.


display alert "What would you like to do" message "Select a network option" buttons {"RetrieveYourIP", "PingIPOrDomainName", "Quit"} cancel button "Quit"
set the button_pressed to the button returned of the result
#Buttons
if the button_pressed is "RetrieveYourIP" then
say "Retrieving Your IP address, this may take a moment." without waiting until completion
WanIP()
display alert "Your IP Address is" & WanIP() & "And has been copied to your clipboard."
set the clipboard to WanIP()
else if the button_pressed is "PingIPOrDomainName" then
set IP_address to ""
set dialog_1 to display dialog "Enter IP Address:" default answer "" with title "Ping IP Address" buttons {"OK"} default button 1
set the IP_address to the text returned of dialog_1
try
do shell script ("ping -c 2 " & IP_address)
display dialog "Host is 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
else
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"} cancel button "Quit"
set the button_pressed to the button returned of the result
#Buttons
if the button_pressed is "VisitApplicationWebSite" then
set VisitApplicationWebSite to "http://firestar-hosting.com/mac"
open location VisitApplicationWebSite
else
if the button_pressed is "FileBugReport" then
set FileBugReport to "http://firestar-hosting.com/mac/bugs"
open location FileBugReport
end if
end if
end if

on WanIP()
set WIP to missing value
set siteList to {"http://checkip.dyndns.org/", "http://whatismyip.com", "http://www.whatismyipaddress.com", "http://ipid.shat.net/", "http://www.edpsciences.comhtbin/ipaddress", "http://www.showmyip.com/"}
repeat with thissite in siteList
try
set WIP to item 1 of paragraphs of (do shell script "curl " & thissite & " | tr -cs '[0-9\\.]' '\\012' | awk -F'.' 'NF==4 && $1>0 && $1<256 && $2<256 && $3<256 && $4<256 && !/\\.\\./'")
if WIP is not missing value then exit repeat
end try
end repeat
return WIP
end WanIP


Yvan KOENIG running Yosemite 10.10.4 in French (VALLAURIS, France) lundi 10 août 2015 17:56:40



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Strange Errors
      • From: Yvan KOENIG <email@hidden>
References: 
 >Strange Errors (From: Daniel Chavez <email@hidden>)

  • Prev by Date: Re: Strange Errors
  • Next by Date: Re: Strange Errors
  • Previous by thread: Strange Errors
  • Next by thread: Re: Strange Errors
  • Index(es):
    • Date
    • Thread