I wrote a small script what among other things will gather a site code, and use that to open a website…
I am sure I am complicating my existence…
I hope this code makes sense and someone can tell me if there is an easier way to do this…
-- SETTINGS
set APCsite to display dialog "What location code you want to visit?" default answer ""
set clubEntered to text returned of APCsite
-- APCsites
set mnar to "10.132.4.11"
set mnav to "10.128.132.11"
set mnbl to "10.128.84.11"
set mnch to "10.129.132.11"
set mncn to "10.130.180.11"
set mncr to "10.128.68.11"
set mned to "10.132.52.11"
-- Safari Application
if text returned of APCsite = "mnar" then
tell application "Safari"
open location "http://" & mnar
end tell
end if
if text returned of APCsite = "mnav" then
tell application "Safari"
open location "http://" & mnav
end tell
end if
if text returned of APCsite = "mnav" then
tell application "Safari"
open location "http://" & mnav
end tell
end if
if text returned of APCsite = "mncn" then
tell application "Safari"
open location "http://" & mncn
end tell
end if
set APCsiteList to {"10.132.4.11", "10.128.132.11", "10.128.84.11", "10.129.132.11", "10.130.180.11", "10.128.68.11", "10.132.52.11"}
set APCsite to choose from list APCsiteList with prompt "What location code you want to visit?"
if APCsite is false then return
tell application "Safari" to open location "http://" & (item 1 of APCsite)
A bit different than I had thought of it… I will play with it a bit and see if this works!
I will be using some more information gathered at the same time, since It will call the site and then click on certain parts of the site to perform some other tasks remotely…
Therefore I would be not only asking for the Site but the areas to control, (which will be performed once the script logs into the site…)
thanks again…
If there is any other suggestions I will appreciate it
I played with your code for some time… but I was not able to get it the way I wanted it
here is something very close to what I want…
I want a window to ask me which location code I want to visit (this is a pre defined name, which is depicted in the code … such as MNAR or MNCN which has an assigned IP address already)
and instead of using a long list as you mentioned, I want to have the user to type the code itself
I have set the location codes but how can I tell the dialog to use the answer (variable) to call the location code?
thanks!
-- SETTINGS
set APCsite to display dialog "What location code you want to visit?" default answer ""
set clubEntered to variable of APCsite
-- APCsites
-- ** Minnesota **
set mnar to "10.132.4.11"
set mnav to "10.128.132.11"
set mnbl to "10.128.84.11"
set mnch to "10.129.132.11"
set mncn to "10.130.180.11"
set mncr to "10.128.68.11"
set mnea to "10.128.4.11"
set mned to "10.132.52.11"
set mnhp to "10.128.52.11"
set mnlv to "10.131.148.11"
set mnmg to "10.131.20.11"
set mnmk to "10.130.212.11"
set mnml to "10.131.244.11"
set mnmn to "10.128.148.11"
set mnnh to "10.130.20.11"
set mnns to "10.132.68.11"
set mnod to "10.132.36.11"
set mnpl to "10.128.116.11"
set mnrv to "10.128.36.11"
set mnsl to "10.132.100.11"
set mnsv to "10.129.180.11"
set mnup to "10.133.148.11"
set mnwb to "10.128.20.11"
set mnwh to "10.128.164.11"
set mnxt to "10.132.20.11"
-- ** Missouri **
set mowc to "10.132.132.11"
-- ** North Carolina **
set nccy to "10.131.100.11"
-- ** Nebraska **
set neoh to "10.131.164.11"
-- ** New Jersey **
set njbh to "10.133.52.11"
set njfp to "10.133.20.11"
tell application "Safari"
activate
open location "http://" & variable
end tell
then try this, you can extend codeList and ipList as much as you want, but the number of items in both lists must be equal
property codeList : {"mnar", "mnav", "mnbl"}
property ipList : {"10.132.4.11", "10.128.132.11", "10.128.84.11"}
set ipAddress to missing value
repeat
set {text returned:APCsite} to display dialog "What location code you want to visit?" default answer ""
if APCsite is not in codeList then
display dialog "Code does not exist" buttons {"Cancel", "Try Again"} default button 2 with icon 2
else
exit repeat
end if
end repeat
repeat with i from 1 to count codeList
if APCsite is item i of codeList then
set ipAddress to item i of ipList
exit repeat
end if
end repeat
if ipAddress is not missing value then
tell application "Safari"
activate
open location "http://" & ipAddress
end tell
end if
The variable APCSitesRaw is just a tab delimited table contents. You can store this content easily into a file and use cat to get the content. I think this list is much easier to maintain.
--this data could also be save inot a file and use cat instead of echo later
set APCsitesRaw to "mnar 10.132.4.11
mnav 10.128.132.11
mnbl 10.128.84.11
mnch 10.129.132.1
mncn 10.130.180.11
mncr 10.128.68.11
mnea 10.128.4.11
mned 10.132.52.11
mnhp 10.128.52.11
mnlv 10.131.148.11
mnmg 10.131.20.11
mnmk 10.130.212.11
mnml 10.131.244.11
mnmn 10.128.148.11
mnnh 10.130.20.11
mnns 10.132.68.11
mnod 10.132.36.11
mnpl 10.128.116.11
mnrv 10.128.36.11
mnsl 10.132.100.11
mnsv 10.129.180.11
mnup 10.133.148.11
mnwb 10.128.20.11
mnwh 10.128.164.11
mnxt 10.132.20.11
mowc 10.132.132.11
nccy 10.131.100.11
neoh 10.131.164.11
njbh 10.133.52.11
njfp 10.133.20.11"
set names to every paragraph of (do shell script "/bin/echo -n " & quoted form of APCsitesRaw & " | awk '{print $1}'")
set theName to choose from list names
if theName is false then
return
end if
set theName to item 1 of theName
set theAddress to (do shell script "/bin/echo -n " & quoted form of APCsitesRaw & " | grep " & theName & "| awk '{print $2}'")
tell application "Safari"
activate
open location "http://" & theAddress
end tell
Going with DJ Bazzie Wazzie’s take, this will allow you to insert a little formatting (by state in this example) so long as you precede it with an asterisk and allows the more straight forward list of pairs.
set APCsites to "** Minnesota **
mnar 10.132.4.11
mnav 10.128.132.11
mnbl 10.128.84.11
mnch 10.129.132.1
mncn 10.130.180.11
mncr 10.128.68.11
mnea 10.128.4.11
mned 10.132.52.11
mnhp 10.128.52.11
mnlv 10.131.148.11
mnmg 10.131.20.11
mnmk 10.130.212.11
mnml 10.131.244.11
mnmn 10.128.148.11
mnnh 10.130.20.11
mnns 10.132.68.11
mnod 10.132.36.11
mnpl 10.128.116.11
mnrv 10.128.36.11
mnsl 10.132.100.11
mnsv 10.129.180.11
mnup 10.133.148.11
mnwb 10.128.20.11
mnwh 10.128.164.11
mnxt 10.132.20.11
** Missouri **
mowc 10.132.132.11
** North Carolina **
nccy 10.131.100.11
** Nebraska **
neoh 10.131.164.11
** New Jersey **
njbh 10.133.52.11
njfp 10.133.20.11"
set APClist to every paragraph of APCsites as list
set APCnames to {}
repeat with i from 1 to count of APClist
set theTitle to first word of item i in APClist
if theTitle is not "*" then
set end of APCnames to theTitle
else
set end of APCnames to item i in APClist
end if
end repeat
repeat
set theName to item 1 of (choose from list APCnames)
if theName is false then
return
else if first character of theName is not "*" then
exit repeat
end if
end repeat
repeat with i from 1 to count of APClist
if first word of item i in APClist is theName then
set theAddress to last word of item i in APClist
exit repeat
end if
end repeat
tell application "Safari"
activate
open location "http://" & theAddress
end tell