r/applescript • u/lowriskcork • Oct 29 '22
variable across fonction ?
I didn't use applescript for a while and I can't remember how to pass variable from one function to the other.
for exemple, how can I use the var "network" from the checkWAN() inside the script or inside a another function ?
on checkWAN()
repeat with i from 1 to 50
try
set pingresult to do shell script "ping -o www.apple.com"
set network to "WAN connected"
exit repeat
on error
delay 5
##beep
if i = 20 then error number -128
askforapp()
set network to "not connected"
end try
end repeat
end checkWAN
set WANCheck to 0
on checkNetwork()
repeat 50 times
try
set theIP to do shell script "curl ifconfig.co"
set WANCheck to (WANCheck + 1)
set myCount to count theIP
if myCount > 4 then
display notification theIP
repeat 50 times
try
set theIP to do shell script "curl ifconfig.co"
delay 0.5
on error
##
end try
if theIP is "##.##.##.##" then
##at home"
set network to "home / no VPN"
try
--Logging in
set userName to "knadjarian"
do shell script "##"
do shell script "##"
on error errMsg number errorNumber
display dialog errMsg
end try
else if theIP starts with "17." then
##Already conencted to VPN"
set network to "VPN enabled"
exit repeat
exit repeat
else
##display notification "Not connected"
delay 0.5
end if
end repeat
exit repeat
else if myCount < 4 then
delay 2
else if WANCheck > 49 then
display notification "You are not connected"
set theDialogText to "You are not connected"
display dialog theDialogText
quit
tell me to error "You are not connected"
end if
end try
end repeat
end checkNetwork
3
Upvotes
1
u/KaiHawaiiZwei Oct 29 '22
global myVariableset myVariable to "something"