Time limits on specific apps in macOS High Sierra

Solution 1:

Note: I myself am a kid too, hopefully others don't see me as a traitor for providing this answer 🤣🤣

Heres the start of my application. It is a work in progress. I will be editing very soon to include may new features such as

  • Remote editing of settings (like parental controls allows you to do)

  • Ability to get alerted if the kid tries to bypass the restriction

  • Ability to extend time (reward system?) with a parental password

  • Ability to bypass restriction completely with parental password

  • Multiple Alerts

  • More Logs

  • More comments in code

  • LaunchAgent and LaunchDemon

  • Many more features

Open this in Script Editor and export it as a read-only application and make sure stay open after run handler is checked off

After exporting follow this guide to prevent it from show up in the dock.

To quit, go to Activity Monitor, search for what ever you saved the application as and press the X in the upper left hand corner of the window.

 ## Time Limiter - Created by Josh Brown - Created June 8th 2018 - Last Modified June 8th 2018 ##
global applist
global timelimit
global timelimits
global day1
global day2


## Settings ##
set applist to {"Google Chrome", "App Store"} -- Apps to limit
set timelimit to 10 -- time to limit in min, this is cumulative between all application
set alert1 to 5 -- time when to give a warning (great for giving a 5 min warning so they know they should save and wrap up what they are doing)

## Alert Settings ##
set alertme to false
set bypassattempts to 0
set maxbypassattemtps to 3 -- If the kid trys to reopen application after timelimit has expired alert you

## Bypass/Extention Settings ## -- If you would like to give the kid an extesion or bypass the block
set allowbypass to false
set pass1 to ""



set timelimit to timelimit * 60 -- Make into a seconds
set alert1 to alert1 * 60

set timelimits to timelimit

on is_running(appName)
    tell application "System Events" to (name of processes) contains appName
end is_running

on checkapps()
    set x to false
    repeat with a from 1 to length of applist
        set b to item a of applist
        if is_running(b) then
            set x to true
        end if
    end repeat
    return x
end checkapps

on killall()
    tell application "System Events"
        repeat with myProcess in applist
            set theID to (unix id of processes whose name is myProcess)
            try
                do shell script "kill -9 " & theID
            end try
        end repeat
    end tell
end killall

on logme(msg)
    set time1 to do shell script "date"
    do shell script "echo \"" & msg & " " & time1 & "\" >> ~/Library/Logs/Time_Limit.log"
end logme

on checkday()
    if day of (current date) is not equal to day1 then
        set timelimit to timelimit + timelimits
        set day1 to day of (current date)
    end if
end checkday

logme("Begin Timer with Apps List: " & (applist as string))
set day1 to day of (current date)
repeat while 1 = 1
    checkday()
    if checkapps() then
        if timelimit > 0 then
            set timelimit to timelimit - 1
            if timelimit is alert1 then
                logme("Time Left:" & (timelimit as string) & "Displaying alert")
                display notification "Please finsh what you are doing and save your work" with title "Time Limit Almost Up" subtitle ((timelimit * 60) & " Minitues remaing") as string
            end if
        else
            (*
            tell application app1
                quit
            end tell
            delay 20
            *)
            if checkapps() then
                killall()
                logme("App Runnning after Limit, Killing")
            end if
        end if
    end if
    delay 1
end repeat