need help with a stay open script to tell me network activity

i’d say i’m quite a newbie with applescript still. i wrote this script to get the network data in and out from activity monitor and tell me when the total reaches a certain value. everything seems to be going fine except that whenever the script rechecks the values, it will switch to activity monitor window and then to the open script window. i can foresee this being irritating as i’m planning on having the script open almost 24/7. would anyone be kind enough to advise me on what to do? thanks in advance.

this is what i have so far.

script x
	activate application "Activity Monitor"
	tell application "System Events"
		tell process "Activity Monitor"
			-- GUI Scripting statements:
			click radio button "Network" of tab group 1 of window "Activity Monitor"
			get value of static text 8 of tab group 1 of window "Activity Monitor"
			copy result as string to data_in_text
			get value of static text 4 of tab group 1 of window "Activity Monitor"
			copy result as string to data_out_text
		end tell
	end tell
	
	tell application "System Events"
		tell process "Script Editor"
			set frontmost to true
		end tell
	end tell
	
	-- Making data in into a number
	set pathdl to " "
	set char to ""
	set oldlength to 1
	set data_in_num to ""
	global data_in_num
	set revdata_in_num to ""
	
	repeat until char is pathdl
		set char to character oldlength of data_in_text
		set revdata_in_num to revdata_in_num & char
		set oldlength to oldlength + 1
	end repeat
	
	set newlength to (length of revdata_in_num) - 1
	
	repeat with j from 1 to newlength by 1
		set char to character j of revdata_in_num
		set data_in_num to data_in_num & char
	end repeat
	set data_in_num to data_in_num as number
	
	-- Making data out into a number
	
	set pathdl to " "
	set char to ""
	set oldlength to 1
	set data_out_num to ""
	global data_out_num
	set revdata_out_num to ""
	
	repeat until char is pathdl
		set char to character oldlength of data_out_text
		set revdata_out_num to revdata_out_num & char
		set oldlength to oldlength + 1
	end repeat
	
	set newlength to (length of revdata_out_num) - 1
	
	repeat with j from 1 to newlength by 1
		set char to character j of revdata_out_num
		set data_out_num to data_out_num & char
	end repeat
	
	set data_out_num to data_out_num as number
end script
run x


-- repeat calculations until total reaches desired value
repeat
	run x
	data_in_num + data_out_num
	if result is greater than or equal to 4.5 then
		display dialog "Data input = " & data_in_num & " GB" & ¬
			return & "Data output = " & data_out_num & " GB" & ¬
			return & "Total network traffic = " & (data_in_num + data_out_num) & ¬
			" GB" buttons {"Change IP address", "Never mind"} default button 1 with icon 1
		copy result as list to {button_returned}
		if button_returned is "Change IP address" then
			-- change ip in system prefs command	
			tell application "Finder"
				open file "IP change" in folder "Desktop" in folder "faizalfarokh" in folder "Users" in disk 1
			end tell
			exit repeat
		end if
	end if
	delay 30
end repeat

Model: iBook G4
AppleScript: v2.1 (80)
Browser: Safari v2.0 (412)
Operating System: Mac OS X (10.4)

is generated by

script x
   activate application "Activity Monitor"--Sets Activity Monitor windows to the front 
   tell application "System Events"
 --script lines
   end tell
   
   tell application "System Events"
       tell process "Script Editor"
           set frontmost to true--Sets Script Editor's windows to the front
       end tell
   end tell

If your script relies on these windows being open, you may want to seek out a new approach.

SC

silly me, such simple mistakes :/. took the ‘activate’ out of the script x and deleted the tell block with the frontmost and it’s working alright. thanks for pointing it out, sitcom :D.

Ditto here. That’s quite a script for a newbie :lol:

well i was lying, i’m really an expert scripter just pretending to be a newbie. lol seriously though, i took parts of it from somewhere else but i figured since i’m not gonna profit off the guy, no harm done right?

Model: iBook G4
AppleScript: v2.1 (80)
Browser: Safari v2.0 (412)
Operating System: Mac OS X (10.4)

True about the profit motive, but it is protocol to credit a scripter for his work. This is best illustrated when someone asks for help on ‘thier’ script. If it gets technical, and you start spittin out techy terms, the “scripter” will then have to fess up, “Well, I didn’t really script this… so I don’t know what your talking about”. That’s the worst kind of newbie
SC
“Aint no future in your frontin”:mad:

:lol: