- Code: Select all
(*
Based on:
http://www.perceptiveautomation.com/wiki/doku.php?id=applescript_snippit
http://www.perceptiveautomation.com/userforum/viewtopic.php?f=11&t=6237&p=37246&hilit=import+variable+from+applescript#p37246
http://applehelpwriter.com/2013/07/30/applescript-get-your-external-ip-address/
This script will deteremine your public internet IP address (aka 'External IP') and import it in to IndigoServer as a variable.
The script is set to display 'No connection' after a pretty short 3-second timeout. Feel free to increase that at the line in the script after the comment "# CHANGE THE DELAY HERE…". Just change the number '3' to something longer (the number = seconds).
*)
property theNetwork : ""
property extIP : ""
set myip to "myIPaddress_Current"
on setVariable(theVariable, theValue)
tell application "IndigoServer"
if variable theVariable exists then
set value of variable theVariable to theValue
else
make new variable with properties {name:theVariable, value:theValue}
end if
end tell
end setVariable
on getIP()
try
set myTemp to do shell script "mktemp -t txt"
do shell script "curl -s http://checkip.dyndns.org &> " & myTemp & " &2> /dev/null"
# CHANGE THE DELAY HERE…
delay 10
set extIP to do shell script "sed 's/[a-zA-Z/<> :]//g' " & myTemp
if extIP = "" then
set my theNetwork to "No connection"
else if extIP contains "=" then
set theNetwork to "Can't get IP"
else
set theNetwork to extIP
end if
on error
set theNetwork to "No connection"
end try
end getIP
repeat
try
getIP()
if result = "Try Again" then
getIP()
else if theNext = "Copy" then
getCopyItem()
exit repeat
end if
on error
exit repeat
end try
end repeat
setVariable(myip, theNetwork)
I found a python module that I think will be more reliable, if I can get it to run.
https://pypi.python.org/pypi/ipgetter
When I run "python -m ipgetter" from my terminal it almost instantly returns my IP. How can I capture this output in a variable as I've been doing?
Thanks,
- Ben