Status of Internet connection to a text field?

Hi Folks,

has anyone an idea on “how to display a status in a textfield”?


on action theObject
	if name of theObject is "status" then
		tell application "Internet Connect"
			set status to state of status of configuration	
		end tell
		set content of text field "status" of tab view item "Connection" of tab view "tab" of window id 1 to status
	end if
end action

This should display the status of the connection to the Textfield - but it will not do it…

any ideas?

Thanks for your help,

Best regards,

Stefan

on action theObject
	if name of theObject is "status" then
		tell application "Internet Connect"
			set con_status to state of status of configuration
			
		end tell
		set content of text field "status" of tab view item "Connection" of tab view "tab" of window id 1 to con_status
	end if
end action

Changing the variable from status to con_status has not resolved this issue…

Best Regards,

Stefan

Hi,

OMM in Script Editor this

tell application "Internet Connect" to set con_status to state of status of configuration

returns an error.

This

tell application "Internet Connect" to set con_status to state of status of configurations

returns {0, 0, 0} . i.e. a list of integers.

Have you tried setting the content of the text field to the variable as text?

set content of text field "status" of tab view item "Connection" of tab view "tab" of window id 1 to (con_status as text)

Best wishes

John M

Hi John,

I have set


on action theObject
	if name of theObject is "con_status" then
		tell application "Internet Connect"
			set con_status to state of status of configuration 1
			return 1
		end tell
		set content of text field "con_status" of tab view item "Connection" of tab view "tab" of window id 1 to (con_status as text)
	end if
end action

configuration to configuration 1

The text field = con_status

But I am not able to see the status…

Is the syntax correct "if name of theObject is “con_status”… ?

Thanks for your help,

Stefan

Hi Stefan,

if name of theObject is "con_status" then

Some questions:
How are you triggering the ‘on action’ handler? Do you have an interface element named “con_ststus” set up to trigger the handler? (ie linked to the handler in IB) How are you expecting the text field to update? The ‘on action’ handler needs an action to trigger it.

John M

Hi John,

I already thought that the error must be there…

I have set the text field “conn_status” to action (apple button +8 in xcode)

may you can give me some advice or hints on how to solve this issue…

thanks for your help!

Stefan



on awake from nib

tell application "Internet Connect"
	set con_status to state of status of configuration 1
	return 1
end tell
set content of text field "con_status" of tab view item "Connection" of tab view "tab" of window id 1 to (con_status as text)

end awake from nib

 

Now I tried to let the state to wake from nib - but with no results - no state will be displayed...:/

Best Regards,

Stefan

PS: I don´t have a documentation right now, but am I correct that return 1 means to return the command every second?

Hi Stefan,

Try this:

on awake from nib
	-- Should make text field "con_status" contain 1
	set contents of text field "con_status" of tab view item "Connection" of tab view "tab" of window id 1 to (1 as text)
end awake from nib

If that works try:

on action theObject
   if name of theObject is "con_status" then
       tell application "Internet Connect"
           set con_status to state of status of configuration 1
       end tell
       set contents of text field "con_status" of tab view item "Connection" of tab view "tab" of window id 1 to (con_status as text)
   end if
end action

‘return’ exits the handler (‘on action’, ‘on awake from nib’, etc). ‘return 1’ only means return every second in an ‘on idle’ handler (this is a special case), in the current case it would mean exit the ‘awake from nib’ handler with a result of 1.

John M

Hi John

thanks a lot for your help! This works - the state will be presented with 0 to 8!

now I have to find out on how to present not a number but a text and how to
present the actual state (which means that the con_status should be refreshed every second)

Thanks a lot and best regards,

Stefan

The Code for displaying the correct status as text:


set con_status to state for status of configuration 1 as string

if con_status is "0" then
set text_status to "Disconnected"
end if

set contents for text field "con_status" of tab view item "Connection" of tab view "tab" of window id 1 to (text_status as text)

How to refresh? Can this be done with a loop?

Best regards,

Stefan

Hi Stefan,

You should be able to use the ‘on idle’ handler.

Take a look at ‘section A’ on this page. You do not need to add any scripting additions to make this work.

on idle theObject
	-- Your working code here.
	return 1 -- seconds
end idle

Best wishes

John M

Hi John,


on idle theObject
	tell application "Internet Connect"
		
		set con_status to state of status of configuration 1 as string
		
	end tell
	if con_status is "0" then
		set text_status to "Nicht verbunden"
	else if con_status is "1" then
		set text_status to "Irgendwas"
	else if con_status is "2" then
		set text_status to "Irgendwo"
	else if con_status is "3" then
		set text_status to "Irgendwann"
	else if con_status is "8" then
		set text_status to "Verbunden"
	end if
	
	set contents of text field "con_status" of tab view item "Connection" of tab view "tab" of window id 1 to (text_status as text)
	return 1
end idle


return 1 - shows only status 2 → then it will not show more…


return 60 * minutes

will also not solve the problem…

Best regards,

Stefan

back,back,back


return 1

works fine - but you have to take care that all of the state are possible - otherwise you will have
an error message!

Best regards,

Stefan