Applescript: check if string is inside of another string [closed] - applescript
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have a basic AppleScript programme that basically pings a bunch of servers and gets the results, put's it into a list, and then the user selects from that list. I need to see if the user's choice contains a string. Say "Midwest". I cannot figure out why my comparison (last few lines) are returning false... Here is my script (sorry, it is kind of long).
tell application "Viscosity" to disconnectall
delay 2
set asdf to 10
--16.33
set address to "us-midwest.privateinternetaccess.com"
repeat with theIncrementValue from 1 to asdf
set {pingmstime, errmsg} to my getpingmstime(address)
if pingmstime is not false then
tell me
activate
--display dialog "Address: " & address & return & "Time: " & pingmstime
end tell
else
tell me
activate
display dialog "Something went wrong:" & return & return & errmsg
end tell
end if
if theIncrementValue is equal to 1 then set midwest1 to pingmstime
if theIncrementValue is equal to 2 then set midwest2 to pingmstime
if theIncrementValue is equal to 3 then set midwest3 to pingmstime
if theIncrementValue is equal to 4 then set midwest4 to pingmstime
if theIncrementValue is equal to 5 then set midwest5 to pingmstime
if theIncrementValue is equal to 6 then set midwest6 to pingmstime
if theIncrementValue is equal to 7 then set midwest7 to pingmstime
if theIncrementValue is equal to 8 then set midwest8 to pingmstime
if theIncrementValue is equal to 9 then set midwest9 to pingmstime
if theIncrementValue is equal to 10 then set midwest10 to pingmstime
if theIncrementValue is equal to 10 then set midwest to ((midwest1 + midwest2 + midwest3 + midwest4 + midwest5 + midwest6 + midwest7 + midwest8 + midwest9 + midwest10) / 10)
end repeat
on getpingmstime(address)
try
set output to do shell script "ping -c 1 " & address
set outputline to (item 2 of (paragraphs of output))
set esoffset to offset of "=" in (reverse of (characters of outputline)) as text
set mstime to (characters -(esoffset - 1) through -4 of outputline) as text
return {mstime, missing value}
on error errmsg number errnum
return {false, errmsg}
end try
end getpingmstime
set address to "us-east.privateinternetaccess.com"
repeat with theIncrementValue from 1 to asdf
set {pingmstime, errmsg} to my getpingmstime(address)
if pingmstime is not false then
tell me
activate
--display dialog "Address: " & address & return & "Time: " & pingmstime
end tell
else
tell me
activate
display dialog "Something went wrong:" & return & return & errmsg
end tell
end if
if theIncrementValue is equal to 1 then set east1 to pingmstime
if theIncrementValue is equal to 2 then set east2 to pingmstime
if theIncrementValue is equal to 3 then set east3 to pingmstime
if theIncrementValue is equal to 4 then set east4 to pingmstime
if theIncrementValue is equal to 5 then set east5 to pingmstime
if theIncrementValue is equal to 6 then set east6 to pingmstime
if theIncrementValue is equal to 7 then set east7 to pingmstime
if theIncrementValue is equal to 8 then set east8 to pingmstime
if theIncrementValue is equal to 9 then set east9 to pingmstime
if theIncrementValue is equal to 10 then set east10 to pingmstime
if theIncrementValue is equal to 10 then set east to ((east1 + east2 + east3 + east4 + east5 + east6 + east7 + east8 + east9 + east10) / 10)
end repeat
set address to "us-west.privateinternetaccess.com"
repeat with theIncrementValue from 1 to asdf
set {pingmstime, errmsg} to my getpingmstime(address)
if pingmstime is not false then
tell me
activate
--display dialog "Address: " & address & return & "Time: " & pingmstime
end tell
else
tell me
activate
display dialog "Something went wrong:" & return & return & errmsg
end tell
end if
if theIncrementValue is equal to 1 then set west1 to pingmstime
if theIncrementValue is equal to 2 then set west2 to pingmstime
if theIncrementValue is equal to 3 then set west3 to pingmstime
if theIncrementValue is equal to 4 then set west4 to pingmstime
if theIncrementValue is equal to 5 then set west5 to pingmstime
if theIncrementValue is equal to 6 then set west6 to pingmstime
if theIncrementValue is equal to 7 then set west7 to pingmstime
if theIncrementValue is equal to 8 then set west8 to pingmstime
if theIncrementValue is equal to 9 then set west9 to pingmstime
if theIncrementValue is equal to 10 then set west10 to pingmstime
if theIncrementValue is equal to 10 then set west to ((west1 + west2 + west3 + west4 + west5 + west6 + west7 + west8 + west9 + west10) / 10)
end repeat
set address to "us-texas.privateinternetaccess.com"
repeat with theIncrementValue from 1 to asdf
set {pingmstime, errmsg} to my getpingmstime(address)
if pingmstime is not false then
tell me
activate
--display dialog "Address: " & address & return & "Time: " & pingmstime
end tell
else
tell me
activate
display dialog "Something went wrong:" & return & return & errmsg
end tell
end if
if theIncrementValue is equal to 1 then set texas1 to pingmstime
if theIncrementValue is equal to 2 then set texas2 to pingmstime
if theIncrementValue is equal to 3 then set texas3 to pingmstime
if theIncrementValue is equal to 4 then set texas4 to pingmstime
if theIncrementValue is equal to 5 then set texas5 to pingmstime
if theIncrementValue is equal to 6 then set texas6 to pingmstime
if theIncrementValue is equal to 7 then set texas7 to pingmstime
if theIncrementValue is equal to 8 then set texas8 to pingmstime
if theIncrementValue is equal to 9 then set texas9 to pingmstime
if theIncrementValue is equal to 10 then set texas10 to pingmstime
if theIncrementValue is equal to 10 then set texas to ((texas1 + texas2 + texas3 + texas4 + texas5 + texas6 + texas7 + texas8 + texas9 + texas10) / 10)
end repeat
set address to "us-california.privateinternetaccess.com"
repeat with theIncrementValue from 1 to asdf
set {pingmstime, errmsg} to my getpingmstime(address)
if pingmstime is not false then
tell me
activate
--display dialog "Address: " & address & return & "Time: " & pingmstime
end tell
else
tell me
activate
display dialog "Something went wrong:" & return & return & errmsg
end tell
end if
if theIncrementValue is equal to 1 then set california1 to pingmstime
if theIncrementValue is equal to 2 then set california2 to pingmstime
if theIncrementValue is equal to 3 then set california3 to pingmstime
if theIncrementValue is equal to 4 then set california4 to pingmstime
if theIncrementValue is equal to 5 then set california5 to pingmstime
if theIncrementValue is equal to 6 then set california6 to pingmstime
if theIncrementValue is equal to 7 then set california7 to pingmstime
if theIncrementValue is equal to 8 then set california8 to pingmstime
if theIncrementValue is equal to 9 then set california9 to pingmstime
if theIncrementValue is equal to 10 then set california10 to pingmstime
if theIncrementValue is equal to 10 then set california to ((california1 + california2 + california3 + california4 + california5 + california6 + california7 + california8 + california9 + california10) / 10)
end repeat
set address to "us-florida.privateinternetaccess.com"
repeat with theIncrementValue from 1 to asdf
set {pingmstime, errmsg} to my getpingmstime(address)
if pingmstime is not false then
tell me
activate
--display dialog "Address: " & address & return & "Time: " & pingmstime
end tell
else
tell me
activate
display dialog "Something went wrong:" & return & return & errmsg
end tell
end if
if theIncrementValue is equal to 1 then set florida1 to pingmstime
if theIncrementValue is equal to 2 then set florida2 to pingmstime
if theIncrementValue is equal to 3 then set florida3 to pingmstime
if theIncrementValue is equal to 4 then set florida4 to pingmstime
if theIncrementValue is equal to 5 then set florida5 to pingmstime
if theIncrementValue is equal to 6 then set florida6 to pingmstime
if theIncrementValue is equal to 7 then set florida7 to pingmstime
if theIncrementValue is equal to 8 then set florida8 to pingmstime
if theIncrementValue is equal to 9 then set florida9 to pingmstime
if theIncrementValue is equal to 10 then set florida10 to pingmstime
if theIncrementValue is equal to 10 then set florida to ((florida1 + florida2 + florida3 + florida4 + florida5 + florida6 + florida7 + florida8 + florida9 + florida10) / 10)
end repeat
set address to "ca.privateinternetaccess.com"
repeat with theIncrementValue from 1 to asdf
set {pingmstime, errmsg} to my getpingmstime(address)
if pingmstime is not false then
tell me
activate
--display dialog "Address: " & address & return & "Time: " & pingmstime
end tell
else
tell me
activate
display dialog "Something went wrong:" & return & return & errmsg
end tell
end if
if theIncrementValue is equal to 1 then set ca1 to pingmstime
if theIncrementValue is equal to 2 then set ca2 to pingmstime
if theIncrementValue is equal to 3 then set ca3 to pingmstime
if theIncrementValue is equal to 4 then set ca4 to pingmstime
if theIncrementValue is equal to 5 then set ca5 to pingmstime
if theIncrementValue is equal to 6 then set ca6 to pingmstime
if theIncrementValue is equal to 7 then set ca7 to pingmstime
if theIncrementValue is equal to 8 then set ca8 to pingmstime
if theIncrementValue is equal to 9 then set ca9 to pingmstime
if theIncrementValue is equal to 10 then set ca10 to pingmstime
if theIncrementValue is equal to 10 then set ca to ((ca1 + ca2 + ca3 + ca4 + ca5 + ca6 + ca7 + ca8 + ca9 + ca10) / 10)
end repeat
set address to "ca-toronto.privateinternetaccess.com"
repeat with theIncrementValue from 1 to asdf
set {pingmstime, errmsg} to my getpingmstime(address)
if pingmstime is not false then
tell me
activate
--display dialog "Address: " & address & return & "Time: " & pingmstime
end tell
else
tell me
activate
display dialog "Something went wrong:" & return & return & errmsg
end tell
end if
if theIncrementValue is equal to 1 then set catoronto1 to pingmstime
if theIncrementValue is equal to 2 then set catoronto2 to pingmstime
if theIncrementValue is equal to 3 then set catoronto3 to pingmstime
if theIncrementValue is equal to 4 then set catoronto4 to pingmstime
if theIncrementValue is equal to 5 then set catoronto5 to pingmstime
if theIncrementValue is equal to 6 then set catoronto6 to pingmstime
if theIncrementValue is equal to 7 then set catoronto7 to pingmstime
if theIncrementValue is equal to 8 then set catoronto8 to pingmstime
if theIncrementValue is equal to 9 then set catoronto9 to pingmstime
if theIncrementValue is equal to 10 then set catoronto10 to pingmstime
if theIncrementValue is equal to 10 then set catoronto to ((catoronto1 + catoronto2 + catoronto3 + catoronto4 + catoronto5 + catoronto6 + catoronto7 + catoronto8 + catoronto9 + catoronto10) / 10)
end repeat
set address to "uk-london.privateinternetaccess.com"
repeat with theIncrementValue from 1 to asdf
set {pingmstime, errmsg} to my getpingmstime(address)
if pingmstime is not false then
tell me
activate
--display dialog "Address: " & address & return & "Time: " & pingmstime
end tell
else
tell me
activate
display dialog "Something went wrong:" & return & return & errmsg
end tell
end if
if theIncrementValue is equal to 1 then set uklondon1 to pingmstime
if theIncrementValue is equal to 2 then set uklondon2 to pingmstime
if theIncrementValue is equal to 3 then set uklondon3 to pingmstime
if theIncrementValue is equal to 4 then set uklondon4 to pingmstime
if theIncrementValue is equal to 5 then set uklondon5 to pingmstime
if theIncrementValue is equal to 6 then set uklondon6 to pingmstime
if theIncrementValue is equal to 7 then set uklondon7 to pingmstime
if theIncrementValue is equal to 8 then set uklondon8 to pingmstime
if theIncrementValue is equal to 9 then set uklondon9 to pingmstime
if theIncrementValue is equal to 10 then set uklondon10 to pingmstime
if theIncrementValue is equal to 10 then set uklondon to ((uklondon1 + uklondon2 + uklondon3 + uklondon4 + uklondon5 + uklondon6 + uklondon7 + uklondon8 + uklondon9 + uklondon10) / 10)
end repeat
set address to "uk-southampton.privateinternetaccess.com"
repeat with theIncrementValue from 1 to asdf
set {pingmstime, errmsg} to my getpingmstime(address)
if pingmstime is not false then
tell me
activate
--display dialog "Address: " & address & return & "Time: " & pingmstime
end tell
else
tell me
activate
display dialog "Something went wrong:" & return & return & errmsg
end tell
end if
if theIncrementValue is equal to 1 then set uksouthampton1 to pingmstime
if theIncrementValue is equal to 2 then set uksouthampton2 to pingmstime
if theIncrementValue is equal to 3 then set uksouthampton3 to pingmstime
if theIncrementValue is equal to 4 then set uksouthampton4 to pingmstime
if theIncrementValue is equal to 5 then set uksouthampton5 to pingmstime
if theIncrementValue is equal to 6 then set uksouthampton6 to pingmstime
if theIncrementValue is equal to 7 then set uksouthampton7 to pingmstime
if theIncrementValue is equal to 8 then set uksouthampton8 to pingmstime
if theIncrementValue is equal to 9 then set uksouthampton9 to pingmstime
if theIncrementValue is equal to 10 then set uksouthampton10 to pingmstime
if theIncrementValue is equal to 10 then set uksouthampton to ((uksouthampton1 + uksouthampton2 + uksouthampton3 + uksouthampton4 + uksouthampton5 + uksouthampton6 + uksouthampton7 + uksouthampton8 + uksouthampton9 + uksouthampton10) / 10)
end repeat
set address to "swiss.privateinternetaccess.com"
repeat with theIncrementValue from 1 to asdf
set {pingmstime, errmsg} to my getpingmstime(address)
if pingmstime is not false then
tell me
activate
--display dialog "Address: " & address & return & "Time: " & pingmstime
end tell
else
tell me
activate
display dialog "Something went wrong:" & return & return & errmsg
end tell
end if
if theIncrementValue is equal to 1 then set swiss1 to pingmstime
if theIncrementValue is equal to 2 then set swiss2 to pingmstime
if theIncrementValue is equal to 3 then set swiss3 to pingmstime
if theIncrementValue is equal to 4 then set swiss4 to pingmstime
if theIncrementValue is equal to 5 then set swiss5 to pingmstime
if theIncrementValue is equal to 6 then set swiss6 to pingmstime
if theIncrementValue is equal to 7 then set swiss7 to pingmstime
if theIncrementValue is equal to 8 then set swiss8 to pingmstime
if theIncrementValue is equal to 9 then set swiss9 to pingmstime
if theIncrementValue is equal to 10 then set swiss10 to pingmstime
if theIncrementValue is equal to 10 then set swiss to ((swiss1 + swiss2 + swiss3 + swiss4 + swiss5 + swiss6 + swiss7 + swiss8 + swiss9 + swiss10) / 10)
end repeat
set address to "nl.privateinternetaccess.com"
repeat with theIncrementValue from 1 to asdf
set {pingmstime, errmsg} to my getpingmstime(address)
if pingmstime is not false then
tell me
activate
--display dialog "Address: " & address & return & "Time: " & pingmstime
end tell
else
tell me
activate
display dialog "Something went wrong:" & return & return & errmsg
end tell
end if
if theIncrementValue is equal to 1 then set nl1 to pingmstime
if theIncrementValue is equal to 2 then set nl2 to pingmstime
if theIncrementValue is equal to 3 then set nl3 to pingmstime
if theIncrementValue is equal to 4 then set nl4 to pingmstime
if theIncrementValue is equal to 5 then set nl5 to pingmstime
if theIncrementValue is equal to 6 then set nl6 to pingmstime
if theIncrementValue is equal to 7 then set nl7 to pingmstime
if theIncrementValue is equal to 8 then set nl8 to pingmstime
if theIncrementValue is equal to 9 then set nl9 to pingmstime
if theIncrementValue is equal to 10 then set nl10 to pingmstime
if theIncrementValue is equal to 10 then set nl to ((nl1 + nl2 + nl3 + nl4 + nl5 + nl6 + nl7 + nl8 + nl9 + nl10) / 10)
end repeat
set address to "sweden.privateinternetaccess.com"
repeat with theIncrementValue from 1 to asdf
set {pingmstime, errmsg} to my getpingmstime(address)
if pingmstime is not false then
tell me
activate
--display dialog "Address: " & address & return & "Time: " & pingmstime
end tell
else
tell me
activate
display dialog "Something went wrong:" & return & return & errmsg
end tell
end if
if theIncrementValue is equal to 1 then set sweden1 to pingmstime
if theIncrementValue is equal to 2 then set sweden2 to pingmstime
if theIncrementValue is equal to 3 then set sweden3 to pingmstime
if theIncrementValue is equal to 4 then set sweden4 to pingmstime
if theIncrementValue is equal to 5 then set sweden5 to pingmstime
if theIncrementValue is equal to 6 then set sweden6 to pingmstime
if theIncrementValue is equal to 7 then set sweden7 to pingmstime
if theIncrementValue is equal to 8 then set sweden8 to pingmstime
if theIncrementValue is equal to 9 then set sweden9 to pingmstime
if theIncrementValue is equal to 10 then set sweden10 to pingmstime
if theIncrementValue is equal to 10 then set sweden to ((sweden1 + sweden2 + sweden3 + sweden4 + sweden5 + sweden6 + sweden7 + sweden8 + sweden9 + sweden10) / 10)
end repeat
set address to "france.privateinternetaccess.com"
repeat with theIncrementValue from 1 to asdf
set {pingmstime, errmsg} to my getpingmstime(address)
if pingmstime is not false then
tell me
activate
--display dialog "Address: " & address & return & "Time: " & pingmstime
end tell
else
tell me
activate
display dialog "Something went wrong:" & return & return & errmsg
end tell
end if
if theIncrementValue is equal to 1 then set france1 to pingmstime
if theIncrementValue is equal to 2 then set france2 to pingmstime
if theIncrementValue is equal to 3 then set france3 to pingmstime
if theIncrementValue is equal to 4 then set france4 to pingmstime
if theIncrementValue is equal to 5 then set france5 to pingmstime
if theIncrementValue is equal to 6 then set france6 to pingmstime
if theIncrementValue is equal to 7 then set france7 to pingmstime
if theIncrementValue is equal to 8 then set france8 to pingmstime
if theIncrementValue is equal to 9 then set france9 to pingmstime
if theIncrementValue is equal to 10 then set france10 to pingmstime
if theIncrementValue is equal to 10 then set france to ((france1 + france2 + france3 + france4 + france5 + france6 + france7 + france8 + france9 + france10) / 10)
end repeat
set address to "germany.privateinternetaccess.com"
repeat with theIncrementValue from 1 to asdf
set {pingmstime, errmsg} to my getpingmstime(address)
if pingmstime is not false then
tell me
activate
--display dialog "Address: " & address & return & "Time: " & pingmstime
end tell
else
tell me
activate
display dialog "Something went wrong:" & return & return & errmsg
end tell
end if
if theIncrementValue is equal to 1 then set germany1 to pingmstime
if theIncrementValue is equal to 2 then set germany2 to pingmstime
if theIncrementValue is equal to 3 then set germany3 to pingmstime
if theIncrementValue is equal to 4 then set germany4 to pingmstime
if theIncrementValue is equal to 5 then set germany5 to pingmstime
if theIncrementValue is equal to 6 then set germany6 to pingmstime
if theIncrementValue is equal to 7 then set germany7 to pingmstime
if theIncrementValue is equal to 8 then set germany8 to pingmstime
if theIncrementValue is equal to 9 then set germany9 to pingmstime
if theIncrementValue is equal to 10 then set germany10 to pingmstime
if theIncrementValue is equal to 10 then set germany to ((germany1 + germany2 + germany3 + germany4 + germany5 + germany6 + germany7 + germany8 + germany9 + germany10) / 10)
end repeat
set address to "ro.privateinternetaccess.com"
repeat with theIncrementValue from 1 to asdf
set {pingmstime, errmsg} to my getpingmstime(address)
if pingmstime is not false then
tell me
activate
--display dialog "Address: " & address & return & "Time: " & pingmstime
end tell
else
tell me
activate
display dialog "Something went wrong:" & return & return & errmsg
end tell
end if
if theIncrementValue is equal to 1 then set ro1 to pingmstime
if theIncrementValue is equal to 2 then set ro2 to pingmstime
if theIncrementValue is equal to 3 then set ro3 to pingmstime
if theIncrementValue is equal to 4 then set ro4 to pingmstime
if theIncrementValue is equal to 5 then set ro5 to pingmstime
if theIncrementValue is equal to 6 then set ro6 to pingmstime
if theIncrementValue is equal to 7 then set ro7 to pingmstime
if theIncrementValue is equal to 8 then set ro8 to pingmstime
if theIncrementValue is equal to 9 then set ro9 to pingmstime
if theIncrementValue is equal to 10 then set ro10 to pingmstime
if theIncrementValue is equal to 10 then set ro to ((ro1 + ro2 + ro3 + ro4 + ro5 + ro6 + ro7 + ro8 + ro9 + ro10) / 10)
end repeat
set address to "hk.privateinternetaccess.com"
repeat with theIncrementValue from 1 to asdf
set {pingmstime, errmsg} to my getpingmstime(address)
if pingmstime is not false then
tell me
activate
--display dialog "Address: " & address & return & "Time: " & pingmstime
end tell
else
tell me
activate
display dialog "Something went whkng:" & return & return & errmsg
end tell
end if
if theIncrementValue is equal to 1 then set hk1 to pingmstime
if theIncrementValue is equal to 2 then set hk2 to pingmstime
if theIncrementValue is equal to 3 then set hk3 to pingmstime
if theIncrementValue is equal to 4 then set hk4 to pingmstime
if theIncrementValue is equal to 5 then set hk5 to pingmstime
if theIncrementValue is equal to 6 then set hk6 to pingmstime
if theIncrementValue is equal to 7 then set hk7 to pingmstime
if theIncrementValue is equal to 8 then set hk8 to pingmstime
if theIncrementValue is equal to 9 then set hk9 to pingmstime
if theIncrementValue is equal to 10 then set hk10 to pingmstime
if theIncrementValue is equal to 10 then set hk to ((hk1 + hk2 + hk3 + hk4 + hk5 + hk6 + hk7 + hk8 + hk9 + hk10) / 10)
end repeat
--display dialog midwest & " - Midwest"
set midwest2 to midwest & " - US, Midwest"
set east2 to east & ", US, East"
set west2 to west & " - US, West"
set texas2 to texas & " - US, Texas"
set california2 to california & " - US, California"
set ca2 to ca & " - Canada"
set catoronto2 to catoronto & " - Canada, Toronto"
set uklondon2 to uklondon & " - UK, London"
set uksouthampton2 to uksouthampton & " - UK, Southampton"
set swiss2 to swiss & " - Switzerland"
set nl2 to nl & " - Netherlands"
set sweden2 to sweden & " - Sweden"
set france2 to france & " - France"
set germany2 to germany & " - Germany"
set ro2 to ro & " - Romania"
set hk2 to hk & " - Hong Kong"
set the_list to {midwest2, east2, west2, texas2, california2, ca2, catoronto2, uklondon2, uksouthampton2, swiss2, nl2, sweden2, france2, germany2, ro2, hk2}
(*set old_delims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {ASCII character 10} -- always a linefeed
set list_string to (the_list as string)
set new_string to do shell script "echo " & quoted form of list_string & " | sort -f"
set new_list to paragraphs of (do shell script "echo " & quoted form of (the_list as string) & "| sort -d -f")
set AppleScript's text item delimiters to old_delims
--return new_list
set theResult to choose from list new_list
if theResult contains "Midwest" then
display dialog theResult
end if*)
--set the composer_list to the_list
--simple_sort(the the_list)
--on simple_sort(my_list)
set the index_list to {}
set the sorted_list to {}
repeat (the number of items in the_list) times
set the low_item to ""
repeat with i from 1 to (number of items in the_list)
if i is not in the index_list then
set this_item to item i of the_list as text
if the low_item is "" then
set the low_item to this_item
set the low_item_index to i
else if this_item comes before the low_item then
set the low_item to this_item
set the low_item_index to i
end if
end if
end repeat
set the end of sorted_list to the low_item
set the end of the index_list to the low_item_index
end repeat
set theResult to choose from list sorted_list with title "Here are the Servers in order from slowest to fastest..."
--display dialog theResult
set theResult2 to theResult
--return the sorted_list
--end simple_sort
--set theResult to choose from list sorted_list
Ok, this is where is is acting up, and not working. The comparison comes back as not being equal, even though the strings are in fact equal. Even if I do choose "Midwest", it is not working. I have scoured the internet for this and cannot figure out why it won't compare:
if midwest2 is equal to theResult2 then display dialog "You chose Midwest"
if not midwest2 is equal to theResult then display dialog "You didn't choose \"" & midwest2 & ". You chose \"" & theResult & "\""
if west2 is in theResult2 then display dialog "You chose West"
Choose from list returns a list, not text. You can't compare a list to text
return {"a"} = "a"
Try this instead:
set theResult to choose from list sorted_list with title "Here are the Servers in order from slowest to fastest..."
if theResult is false then
error number -128
else
set theResult to first item of theResult
end if
Related
logical calculation using &, ~ in sybase
I am executing the below statements. SELECT 10 & ~3 . this gives the output as 8 SELECT 10 & ~5 . this gives the output as 10 SELECT 10 & ~2 . this gives the output as 8 Can anyone explain the logic behind this?
this is bitwise operations, and ~ is inverse. 3 is the same as 0011 in binary, and inverse of that is 1100 2 is the same as 0010 in binary, and inverse of that is 1101 5 is the same as 0101 in binary, and inverse of that is 1010 10 is the same as 1010 in binary. 10 & ~3 => 1010 & 1100 = 1000 => 8 10 & ~5 => 1010 & 1010 = 1010 => 10 10 & ~2 => 1010 & 1101 = 1000 => 8 bitwise is bit for bit you can think in decimal as well, but you have to have your mindset in binary as well (sequence 1, 2, 4, 8, 16, 32, 64, 128...). 10 consist of "8 | 2" and 3 consist of "1 | 2". Inverse of 3 is all but "1 | 2". Common part between 10 and 3 is 2 so you will have all parts from 10 that is not in 3, thus giving us 8.
Nested Loop: to be dynamic?
Ok i'm actually doing this exercise to tackle those nested loop questions. I would say this would be the hardest one for me. I tried my best to be more dynamic instead of static. Can anyone give me tips on how to solve this? expected output: 1 1 2 1 2 4 1 2 4 8 1 2 4 8 16 1 2 4 8 16 32 1 2 4 8 16 32 64 1 2 4 8 16 32 64 128 this is my static code: n = 1 for i in 1..8 for c in 1..n case i when 1 print "1" when 2 print "1 2" when 3 print "1 2 4" when 4 print "1 2 4 8" when 5 print "1 2 4 8 16" when 6 print "1 2 4 8 16 32" when 7 print "1 2 4 8 16 32 64" when 8 print "1 2 4 8 16 32 64 128" end print "\n" end end I'm not looking for answer. But i would appreciate that you can guide me.
for x in 0..7 for y in 0..x op = 2**y print op, " " end puts "" end Prints 1 1 2 1 2 4 1 2 4 8 1 2 4 8 16 1 2 4 8 16 32 1 2 4 8 16 32 64 1 2 4 8 16 32 64 128
You need to store the result of every step and add the new step. Ruby doesn't work much with for's, there are better methods such as the .upto method I use here. The inject provides the result variable out at which you can add the step calculation. The " #{2**i} " is the calculation interpolated as a string with a space after. (0.upto 8).inject("") do |out, i| puts out out << "#{2**i} " end Which gives 1 1 2 1 2 4 1 2 4 8 1 2 4 8 16 1 2 4 8 16 32 1 2 4 8 16 32 64 1 2 4 8 16 32 64 128
apple script.. displaying multiple results instead of one. How to fix so it displays one?
I am creating a very basic applescript with of something similar to a magic 8 ball.. but when I enter a number for example answer2 is the number that the person enters and based on the number your result comes up. When I enter any number two dialogues come up. Why is this? if answer2 is less than 3 then display dialog "My sources say yes" if answer2 is greater than or equal to 3 and answer2 is less than or equal to 6 then display dialog "There's a 65% chance of it happening" if answer2 is greater than or equal to 7 and answer2 is less than or equal to 9 then display dialog "Ask me again later" if answer2 is greater than or equal to 10 and answer2 is less than or equal to 13 then display dialog "Yes, as sure as the sky is blue!" if answer2 is greater than or equal to 14 and answer2 is less than or equal to 15 then display dialog "My reply is no" if answer2 is greater than or equal to 15 and answer2 is less than or equal to 17 then display dialog "Outlook not so good" if answer2 is greater than or equal to 18 and answer2 is less than or equal to 20 then display dialog "Signs point to yes" if answer2 is greater than or equal to 20 and answer2 is less than or equal to 23 then display dialog "You can rely on it" if answer2 is greater than or equal to 24 and answer2 is less than or equal to 25 then display dialog "Not in a million years!" if answer2 is greater than or equal to 26 and answer2 is less than or equal to 28 then display dialog "I better not tell you now" if answer2 is greater than or equal to 29 and answer2 is less than or equal to 32 then display dialog "Concentrate and then ask me again" if answer2 is greater than or equal to 33 and answer2 is less than or equal to 35 then display dialog "My sources say no" if answer2 is greater than or equal to 36 and answer2 is less than or equal to 39 then display dialog "You will have to wait" if answer2 is greater than or equal to 40 and answer2 is less than or equal to 43 then display dialog "Don't bet on it" if answer2 is greater than or equal to 44 and answer2 is less than or equal to 45 then display dialog "You can forget about it" if answer2 is greater than or equal to 46 and answer2 is less than or equal to 47 then display dialog "There is a better change of snow in the Sahara" if answer2 is greater than or equal to 48 and answer2 is less than or equal to 50 then display dialog "I am laughing very hard, you better ask again" if answer2 is greater than or equal to 51 and answer2 is less than or equal to 53 then display dialog "The sky is blue, the grass is green, and your answer is yes!" if answer2 is greater than or equal to 54 and answer2 is less than or equal to 57 then display dialog "Very doubtful" if answer2 is greater than or equal to 58 and answer2 is less than or equal to 60 then display dialog "Not in a million years" if answer2 is greater than or equal to 61 and answer2 is less than or equal to 63 then display dialog "I can't decide" if answer2 is greater than or equal to 64 and answer2 is less than or equal to 67 then display dialog "Just google it! " if answer2 is greater than or equal to 68 and answer2 is less than or equal to 70 then display dialog "I don't think so" if answer2 is greater than or equal to 71 and answer2 is less than or equal to 73 then display dialog "The answer is coming to me..just one more second.. sorry I lost it " if answer2 is greater than or equal to 75 and answer2 is less than or equal to 78 then display dialog "Don't ask" if answer2 is greater than or equal to 79 and answer2 is less than or equal to 80 then display dialog "I have no idea" if answer2 is greater than or equal to 81 and answer2 is less than or equal to 84 then display dialog "Sorry, out of psychic coverage range " if answer2 is greater than or equal to 85 and answer2 is less than or equal to 88 then display dialog "Highly unlikely" if answer2 is greater than or equal to 89 and answer2 is less than or equal to 92 then display dialog "Very likely! " if answer2 is greater than or equal to 93 and answer2 is less than or equal to 96 then display dialog "I don't think so.. chances are very low" if answer2 is greater than or equal to 97 and answer2 is less than or equal to 100 then display dialog "The answer is coming to me..just one more second.. sorry I lost it "
display dialog returns a string, not a number. You have to coerce the string to integer Put this right before your code. repeat set answer2 to text returned of (display dialog "Enter a Number" default answer "0") try set answer2 to answer2 as integer exit repeat on error display dialog "I said: Enter a Number" buttons {"Give Up", "Try again"} cancel button 1 default button 2 end try end repeat I recommend to use if- else if - end if syntax for better performance.
ampersand used in SET /A command in Windows batch script
Could you please advice what using "&" or "^" in SET command means (I haven't found any explanation by using Google). For example, following Windows batch code block SET V_COMMAND=3 SET /A V_FLAG="%V_COMMAND%&2" echo VFlag is: %V_FLAG% produces: VFlag is: 2 But I haven't any opinion about what command above does. Also there is another case with "^": SET V_COMMAND=3 SET /A V_FLAG="%V_COMMAND%^3" echo VFlag is: %V_FLAG% For this case output is: VFlag is: 0
Since you are using set /a, the indicated characters are bitwise operators: & = bitwise AND = 1 if both bits are 1 ^ = bitwise XOR = 1 if only one of the two bits is 1 So if a is 10 (1010 in binary) and b is 13 (1101 in binary) 1010 1010 1101 1101 ---- ---- 1000 = a & b 0111 = a ^ b Or in your case with 3 dec = 11 bin and 2 dec = 10 bin 11 11 10 11 -- -- 10 = 3&2 = 2 00 = 3^3 = 0
Those are bitwise operators - & is bitwise AND, and ^ is bitwise XOR. These bitwise operators are only available with SET /A.
Applescript Realistic Keystroke
Is it possible to use Applescript to type text at a randomised speed quickly & efficiently? I have the following script: On run {input, parameters}: tell application "System Events" keystroke "H" delay 0.2 keystroke "i" delay 0.2 keystroke " " delay 0.2 keystroke "t" delay 0.2 keystroke "h" delay 0.2 keystroke "e" delay 0.2 keystroke "r" delay 0.2 keystroke "e" delay 0.2 keystroke "!" delay 0.1 key code 36 delay 0.5 keystroke "H" delay 0.2 keystroke "o" delay 0.1 keystroke "w" delay 0.2 keystroke " " delay 0.1 keystroke "a" delay 0.2 keystroke "r" delay 0.1 keystroke "e" delay 0.2 keystroke " " delay 0.1 keystroke "y" delay 0.2 keystroke "o" delay 0.2 keystroke "u" delay 0.1 keystroke "?" delay 0.2 key code 36 delay 1.0 keystroke "W" delay 0.2 keystroke "h" delay 0.2 keystroke "e" delay 0.1 keystroke "r" delay 0.2 keystroke "e" delay 0.2 keystroke " " delay 0.1 keystroke "d" delay 0.2 keystroke "o" delay 0.2 keystroke " " delay 0.2 keystroke "y" delay 0.2 keystroke "o" delay 0.1 keystroke "u" delay 0.2 keystroke " " delay 0.1 keystroke "w" delay 0.2 keystroke "a" delay 0.1 keystroke "n" delay 0.2 keystroke "t" delay 0.2 keystroke " " delay 0.1 keystroke "t" delay 0.3 keystroke "o" delay 0.2 keystroke " " delay 0.1 keystroke "b" delay 0.2 keystroke "e" delay 0.2 keystroke "g" delay 0.1 keystroke "i" delay 0.2 keystroke "n" delay 0.1 keystroke "?" end tell return input end run I basically, want to type all of the words (for 1 line at least) in one keystroke (or similar command), and then use a random delay such as the below between each key. Is it possible? delay (random number from 0.05 to 1.0)
Solved it - http://christianheilmann.com/2014/01/09/autmating-typing-in-screencasts-with-applescript-or-how-to-look-like-a-hollywood-hacker/ You just need to create a file (I used a .txt file rather than a .js file), specify the location & hey presto. Heres my tweak with randomised text speed: set fc to read POSIX file "/test/testdoc.txt" as «class utf8» set the text item delimiters to (ASCII character 10) set mylines to text items in fc repeat with currentline in mylines write_string(currentline) end repeat on write_string(the_string) tell application "System Events" tell application "textedit" to activate delay 10 repeat with the_character in the_string keystroke the_character delay (random number from 0.05 to 0.25) end repeat key code 36 key code 123 using command down end tell end write_string
If you do not mind that there are no returns then use this: delay 3 set new_array to "h, i, , t, h, e, r, e, !, , h, o, w, , a, r, e, , y, o, u, ?, , w, h, e, r, e, , d, o, , y, o, u, , w, a, n, t, , t, o, , b, e, g, i, n, ?" set AppleScript's text item delimiters to ", " set the list_items to every text item of the new_array set a to list_items set b to count of list_items set c to 0 tell application "System Events" repeat b times set c to c + 1 delay (random number from 0.05 to 0.3) keystroke item c of a end repeat end tell But if you want the returns then use this: delay 3 set a to "h, i, , t, h, e, r, e, !" set b to "h, o, w, , a, r, e, , y, o, u, ?" set c to "w, h, e, r, e, , d, o, , y, o, u, , w, a, n, t, , t, o, , b, e, g, i, n, ?" set AppleScript's text item delimiters to ", " set the list_items to every text item of the a set d to list_items set e to count of list_items set f to 0 set AppleScript's text item delimiters to ", " set the m to every text item of the b set g to m set h to count of m set i to 0 set AppleScript's text item delimiters to ", " set the n to every text item of the c set j to n set k to count of n set l to 0 tell application "System Events" repeat e times set f to f + 1 delay (random number from 0.05 to 0.3) keystroke item f of d end repeat key code 36 repeat h times set i to i + 1 delay (random number from 0.05 to 0.3) keystroke item i of g end repeat key code 36 repeat k times set l to l + 1 delay (random number from 0.05 to 0.3) keystroke item l of j end repeat end tell