on Idle handler - on click handler - Startup Window

Hi Folks,

maybe you can help me solving the following issues:

  1. Is it possible to have a startup window wich closes after 15 seconds - this startupImage should be above the application window…?

  2. In my application I have an Idle Handler and a OnClick Handler

the Idle Handler is refreshing the state of the internect connect (time, sent, received) every second - when I am clicking
the button I mostly get an “internet connect error”, because the connect is during the onIdle handler is busy - changing from 1 seconds to 5 seconds is working fine, but sometimes there alre also errors…

Is it possible to stop the “onIdle” Handler for 5 seconds during the “onClick”?


on idle theObject
	
	--Anzeige Onlinezeit
	tell application "Internet Connect"
		set time_conn to seconds connected of status as string
	end tell
	
	
	set numSeconds to time_conn mod 60
	set temp to time_conn - numSeconds
	set numMinutes to temp div 60
	set numMinutes to numMinutes mod 60
	set temp to (numMinutes * 60) + numSeconds
	set temp to time_conn - temp
	set numHours to temp div 3600
	if numHours < 10 then set numHours to "0" & numHours
	if numMinutes < 10 then set numMinutes to "0" & numMinutes
	set finalTime to numHours & ":" & numMinutes & ":" & numSeconds as string
	
end idle


on clicked theObject
if name of theObject is "Connect" then
		tell window "main"
			set PopupButtonItem to modem_display
		end tell
		
		set theMatrixItem to title of current cell of matrix "theMatrix" of tab view item "Setting" of tab view "tab" of window id 1
		
		-- Check Huawei E220 gprsinternet
		if (PopupButtonItem is "Web'n'walk Box compact") and (theMatrixItem is "HSDPA Internet") then
			tell application "Internet Connect"
				set configName to "HUAWEI Mobile"
				set currentStatus to status of configuration configName
				connect PPP configuration 1 to telephone number "gprsinternet"
				quit
			end tell
		end if
		-- Check Huawei E220 business.gprsinternet
		if (PopupButtonItem is "Web'n'walk Box compact") and (theMatrixItem is "HSDPA Business") then
			tell application "Internet Connect"
				--activate
				set configName to "HUAWEI Mobile"
				set currentStatus to status of configuration configName
				connect PPP configuration 1 to telephone number "business.gprsinternet"
				quit
			end tell
		end if
		
	end if
	
	if name of theObject is "Disconnect" then
		tell application "Internet Connect"
			if modem_display is "Web'n'walk Box compact" then
				set configName to "HUAWEI Mobile"
			end if
			set currentStatus to status of configuration configName
			disconnect configuration configName
		end tell
	end if
end clicked


  1. Is it possible to save the state of a entry until the next time the application will be started? The Field should be the bytes received or sent from internet state - the state should be counted every time a user is connecting to the internet, and should be resetted when pressing a buttons…?
tell application "Internet Connect"
		set bytes_received to bytes received of status as string
	end tell
	set received_print to bytes_received / 1024
	set received_mb to received_print / 1024
	set received_final to received_mb as integer
	
	set contents of text field "print_received" of tab view item "Setting" of tab view "tab" of window id 1 to received_final
	
	-- Anzeige gesendetete Daten	
	tell application "Internet Connect"
		set bytes_sent to bytes sent of status as string
	end tell
	
	set sent_print to bytes_sent / 1024
	set sent_mb to sent_print / 1024
	set sent_final to sent_mb as integer
	set contents of text field "print_sent" of tab view item "Setting" of tab view "tab" of window id 1 to sent_final

Thanks for any suggestions…

Stefan

Model: iBook G4 with 1.2GHZ
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Ciao Stefan,
as you have written your app with AppleScript Studio (at least it seems to me like this) two of your three questions should be easily resolvable:

  1. Create your startup/splash window and open it inside your onAwakeFromNib handler combined with a counter that closes your window after 15 seconds.

  2. If you want to stop the onIdle handler for 5 seconds because you need an exact time result for your statistics, maybe it’s easier just to add these 5 seconds to your final result.

  3. Your app can create a kind of preference file where the values you need can be stored and from where your app can read this information the next time it will be launched. Just have a look at the open for access, read and write commands in the standard additions.
    For example, your app has written the value 1426000 (bytes received) or a list of more useful values into your pref file: you should put inside the awakeFromNib handler an instruction like

set prefFile to [path_to_your_prefFile] as alias
set myPrefs to read prefFile -- (as list, as string, as any data type you need)
set bytesReceived to item 1 of myPrefs
set contents of text field "bytesReceived" of window "main" to bytesReceived
-- etc

Good scripting
Farid

Hi Farid,

Maybe I was a little unspecific with the onIdle and onClick handler - I have tried with 5 seconds, but
then the time I am counting will only refreshed every 5 seconds, and when I am clicking the button,
then it could be that I am just in the time where the refreshing is running - so I have to think about
a solution where the OnIdle Handler stops when onClick is running, and starts when a status has
been reached…

The best solution would be, that the onIdle Handler is only running when the internet connection state is equal
to 8 (Connection is online) - is this possible?

That means

if clause
on Idle theObject
end if clause

thanks for the tipps…

I will do as you have told me and present the results asap!

Thanks for your time and help…

Stefan

Hi Farid,

I have made the following for the OnIdle handler:


on idle theObject
tell application "Internet Connect"
set con_call to state of status as string
end tell

if con_call is not equal to "0" then

...
....
....

end if



I have put the connection state as if clause, so at the moment when I want to connect, the onIdle handler is not running…

Best Regards, and thanks for your help…

Stefan