url check fails

Hello,

this code works in Script editor, but not if executed from an Applescript Application:

property check_URL : "http://www.google.com" as URL  
#this will return the IP address if there is a live connection
try
	set dotted_ to dotted decimal form of host of check_URL
	return true
on error
	return false
end try

.driving me crazy. Wth is going on? worked perfectly in previous versions. I upgraded to 10.10 currently.

Behave flawlessly here under Sierra.

Yvan KOENIG running Sierra 10.12 in French (VALLAURIS, France) mercredi 21 septembre 2016 12:31:51

Simply crazy. My code doesnt work as app, but only from Script editor.
I wrote a simple script to save as idle-application, so you can test out if you get same results like me. :frowning:
Please test this out and report back to me, thank you very much :expressionless:

property check_URL : "http://www.google.com" as URL  

property dd : 0

on run
	set dd to 0
	my check_net()
end run

on idle
	set dd to dd + 1
	set the res to my check_net()
	
	if dd = 12 and res is "Error" then
		my quit_me()
	end if
	return 6
end idle

on quit_me()
	quit
end quit_me

on check_net()
	try
		set dotted_ to dotted decimal form of host of check_URL
		set a to "Connected"
		#return true
	on error err
		set a to "Error"
		#return false
	end try
	display dialog a giving up after 3
end check_net

Hi Joy.

The check_net() handler’s returning the result of the dialog, not the value of a.

Also, the URL you’re checking is compiled into the script as a property, so its values may always be available.

And there seems to be some caching going on too. Even when getting the URL at only at run time, its host and double-dotted form still seem to be available for a while after the router’s switched off.

It only checks the connection to your router anyway. The only reliable way to check a connection is to try it.

Thanks for looking into it, to both :slight_smile:

i use a wifi - mobile - thing therefore ive some problems to connect.

Shane, the little check i do is just a method to have some guarantee that the connection isnt off. Nothing fancy, i know. In the past, this worked fine, so i confide in this little test :wink:

Nigel, thanks for the pointers. I removed the property pointing at the url and changed some little bits of the last handler.still no success. The fact is, that previously this piece of code worked flawlessly.

Lets strip everything now.and again: “dotted decimal form of host of “http://macscripter.net/” cannot be transformed in Type URL” (i translated from German)


	set dotted_ to dotted decimal form of host of "http://macscripter.net/" as URL 

You need parentheses:

set dotted_ to dotted decimal form of host of ("http://macscripter.net/" as URL)

Wow Shane!
that worked, Thanks!
.and i use a ton of brackets, but this.came not into my mind.
Nice!