help for a scriptig novice

HI, I am not a programmer or scripter in any sense, but I told a friend I would help her out. Ineed to write a script that will disconnect her computer from its internet connection every night from 12am to 6 am. She has a tendency to order stuff from the internet in her sleep and then not remember it in the morning. this is no joke. She has a wireless connection, so i guess a script that would disable her airport card for that time would work too.
thanks
Shawn

If your friend can complete an order online in her sleep, then she’s probably capable of turning the AirPort connection back on as well. It may be more effective to buy a simple lamp timer and use it to physically cut the power to her wireless router between those times. Anyway, you asked for a script so here’s one I wrote:

set night_mode to false
set test_time to time of (current date)
if test_time ≥ 0 then if test_time ≤ 21600 then set night_mode to true

activate application "Internet Connect"
tell application "System Events"
	get system attribute "sysv"
	if result is greater than or equal to 4144 then -- Mac OS X 10.3.0
		if UI elements enabled then
			tell application process "Internet Connect" to tell window 1
				if name is not "AirPort" then click button "AirPort" of tool bar 1
				set button_states to name of every button as list
				if button_states contains "Turn AirPort On" then
					if night_mode is false then click button "Turn Airport On"
				else if night_mode is true then
					click button "Turn AirPort Off"
				end if
			end tell
		else
			beep
			display dialog "GUI Scripting is not enabled" & return & return & "Open System Preferences and check Enable Access for Assistive Devices in the Universal Access preference pane, then run this script again." with icon stop
			if button returned of result is "OK" then
				tell application "System Preferences"
					activate
					set current pane to pane "com.apple.preference.universalaccess"
				end tell
			end if
		end if
	else
		beep
		display dialog "This computer cannot run this script" & return & return & "The script uses GUI Scripting technology, which requires an upgrade to Mac OS X 10.3 Panther or newer." with icon caution buttons {"Quit"} default button "Quit"
	end if
end tell
quit application "Internet Connect"

All you have to do is save this to her hard drive, and then set up a recurring iCal event that fires it at the appropriate times. You do that by making a new event, setting its Alarm to “Run Script”, click Other… find your script file, and then ideally you want to set the alarm to fire “1 minutes after.” Set up two such repeating events (one for 12am, the other 6am) don’t worry if the computer is asleep or turned off at these times, iCal should run the script anyway at its next opportunity, and the script will then sort out whether or not the connection should be active.

An interesting post… Will the computers owner know that a script is running in it? Thier ability on the Mac will determine how good a block works. You could approach with many solutions, here’s one that does not require GUI:

The way this is set up, the person will go to a browser, open a window, and it will immediately close… Try again… close…Try again…close… Notice the script running in the dock, quit…Won’t quit due to infinite repeat exiting only at 6am (ability plays its role here… one trip to “Process Viewer” to force quit and its eBay heaven…) Hopefully the frustration of “closing windows” and a script that won’t quit will wake this person out of delerium. Especially if they don’t know how the script works, etc.

I missed something, Ill repost the script in a bit
SC

I left out “return ExecutionTime” on the first post, which completes the idle. I also added a quit handler so if the script is quit, it starts up again. It is by no means a finished product, as it relies on the computer starting up daily… I modeled it after my behavior (I shut down and start up at least once daily). Let us know what you think.
I would like to see other paths to this goal from anyone willing.
SC


--Old chinese saying "There is a time to parse, and a time to operate"
set BootTime to (current date) as string
set StartupTime to current date


set DateStamp to (word 1 of BootTime & ", " & word 2 of BootTime & ", " & word 3 of BootTime & ", " & word 4 of BootTime)
set Targettime to date (DateStamp & " 11:59:59 PM")

--Everytime the script is activated it will calculate "the time until the script activates in seconds"
set ExecutionTime to (Targettime - StartupTime)

on idle (ExecutionTime)
	activate
	
	delay 1 --Allows time rollover from 11:59:59 to 12:00:00 
	--Activates and continues to monitor the time and Browser processes
	set Downtime to {"12", "1", "2", "3", "4", "5"}
	
	repeat
		set TheTime to time string of (current date)
		
		if word 4 of TheTime is "AM" then
			if word 1 of TheTime is in Downtime then
				tell application "System Events"
					set RunningProc to name of processes
					
					if RunningProc contains "Safari" then tell application "Safari" to close windows
					if RunningProc contains "Internet Explorer" then tell application "Internet Explorer" to CloseAllWindows
					
				end tell
			end if
		end if
		if word 1 of TheTime is not in Downtime then exit repeat
	end repeat
	return ExecutionTime
end idle

on quit
	tell application "Finder" to open alias me
end quit

Save as application w/ options
Never show startup screen
Stay open

Go to “Login Items” of “System Preferences”
Add to Login Items

She really doesn’t know how to do much outside of running some applications, so I think we are safe even with the simplest of blocks. I’ll try these out and see what happens.

Thanks alot for the help! I think her husband will be happy, although no more surprise gifts at the door for her.