I have been playing with a script for a couple of days. My god what a Mind F*** to to get it to work.
any way it seems to.
You can set the Hours in the day the young ones can use safari.
If they are out side these Hours then Safari will quit unless you grant more time.
They are also given a set duration to start with. something like 30 minutes.
This will start as soon as the app first kicks in. and finish regardless if Safari is running or not.
Again if they need more time or Its ok for them to have some time out side the ‘Hours’ you can grant this.
The granting of more time is offered when access time is up. Just enter the Minutes where indicated ie. 5 for five minutes, 120 for two hours.
The script will detect when a new day has started and in effect reset to the original allowance.
I use Safari to display all the dialogs. This stops it being used in the background also if the dialogs time out safari will quit.
There is still work to do, Like getting the reset to be more smart.
And I think the grant access is going to be the Main way to control when the young one can and can not use safari.
The Access code works, but it would be nice to use the ‘with administrators Privileges’ I got it to work and pop up b;ah, blah.
But it does not lock out safari, and puts the script on hold.
I will be testing this in a controlled account. and seeing about putting it into a Shell within Launchd ( using Lingon )
property Access_Time : {"17", "18", "19"} -- Set the hours of Access time here in 24s Clock style. do not enter minutes
property Day_ : ""
property text_returned : ""
property Get_Hr : ""
property Get_Day : ""
property time_span : 1 -- set time allowed for that day. here it is 1 minute for testing
property Timer : (time_span) as number
property Adm_check : "mycode" -- set the Access Code for adding more time after access time runs out
property timefromnow_time : (current date) + (Timer * minutes)
get timefromnow_time
set text_returned to ""
set Get_Hr to do shell script "date +'%H'"
set Get_Day to do shell script "date +'%u'"
on idle
tell application "System Events"
if exists (process "safari") then
my access_InTime()
else
return 5
end if
end tell
end idle
get timefromnow_time
on access_InTime()
tell application "Safari"
if (current date) is less than (timefromnow_time) and Get_Hr is in Access_Time and Get_Day is equal to Day_ then
--say "same day" --test
--say "Safari access allowed"
else if (current date) is greater than (timefromnow_time) then
my access_outTime()
else if Get_Hr is in Access_Time and Get_Day is not equal to Day_ then
set Day_ to Get_Day
--say "Safari access allowed"
--say "new day" --test
return 5
else
my access_outTime()
end if
end tell
end access_InTime
on access_outTime()
say "out off access time"
tell application "Safari" -- insures they can not use safari, until dialog is cleared.
display dialog "Access Time at an End" buttons {"Quit", "More time"} default button 1 giving up after 10
end tell
if the button returned of the result is "Quit" then
say "quit-ing Safari"
my Quit_Safari()
else if the button returned of the result is "More time" then
try
my more_time()
on error
beep
say "more time not granted"
tell application "Safari"
display dialog "More Time has not Been granted " & return & return & "This could happen if you do not enter a " & return & "Number for the minutes, The Dialogue time out, Or wrong access code entered" buttons {"OK"} default button 1 giving up after 10
end tell
my Quit_Safari()
end try
else
say " More time not granted :Selection Timed out"
my Quit_Safari()
end if
end access_outTime
on more_time()
say "more Time selected"
--try
tell application "Safari"
display dialog "Enter More Access Time - In Minutes " default answer "" buttons {"Cancel", "Ok"} default button 2 giving up after 10
copy the result as list to {text_returned2, button_pressed}
set returned_time to (text_returned2 * minutes)
if text_returned2 is "" then
my more_time()
end if
end tell
(*
on error
beep
say "Please Enter Number of Minutes"
my more_time()
end try
*)
if button_pressed is "Ok" then
my _access(returned_time)
else
say "more time not granted"
my Quit_Safari()
end if
end more_time
on _access(returned_time)
tell application "Safari"
display dialog "Enter Code" default answer "" buttons {"Cancel", "Ok"} default button 2 giving up after 10 with hidden answer
copy the result as list to {text_returned1, button_pressed}
if button_pressed is "Ok" then
if text_returned1 is equal to Adm_check then
say "More Access Granted"
--- say returned_time
return returned_time
else
say "Wrong Code - More Access Not Granted"
set Adm_check to ""
my Quit_Safari()
end if
end if
end tell
end _access
on Quit_Safari()
tell application "Safari" to quit
return 5
end Quit_Safari
** Edit need to find a way to quit safari if it is in the middle f Downloading.
ignoring application responses
tell application process "Safari" to quit
end ignoring
does not work for that.