Friday, 28 May 2010

How to set Mac OS X parental controls by script

I needed to be able to set the default time to less than 30 minutes.

This script is run by cron every evening to make sure the time is set to 15 minutes:


# Force times to a lower value than the usual default.

# 15 minutes
/usr/bin/dscl . mcxexport /Users/$USER -o /tmp/usertimes$$.exp \ limits-list
awk -v TVAL=$TVAL 'BEGIN { flag=0 } /timeLimitSeconds/ { flag=1;print;next } \
flag == 1 { $1="<integer>" TVAL "</integer>"; flag=0} \
{print}' < /tmp/usertimes$$.exp > /tmp/usertimesnew$$.exp
/usr/bin/dscl . mcximport /Users/$USER /tmp/usertimesnew$$.exp
/bin/rm -f /tmp/usertimes$$.exp /tmp/usertimesnew$$.exp

Replace "user" with the login of the user you want to change.

Please let me know if there is an easier or more elegant way of doing this.

1 comment:

Roger Pack said...

sweet., worked for me with 10.6.8 [odd that you can't enter arbitrary values in the UI for the time limits...]