Read the Intro
In the following tutorial you will do the following:
- Create a Configuration Profile that will block applications in a certain path
- An application that will add and remove the profile depending on the day
- A LaunchDaemon that will run the application every interval (5 min)
Create the App
Open this in Script Editor and export it as a read-only application and make sure stay open after run handler is not on
After exporting follow this
guide to prevent it from show up in the dock.
# Block Apps Based on Day By Josh Brown
# Last Modified: Aug 23 2018
on run
if checkDay("Friday") then
do shell script "sudo profiles remove -forced -identifier com.company.macos.blockapps"
else
do shell script "sudo profiles install forced -path /path/to/the.mobileconfig"
end if
end run
on checkDay(myDay)
set currentDay to weekday of (get current date)
if (currentDay as string) is (myDay as string) then
return true
else
return false
end if
end checkDay
Create the Mobile Config
Use
<key>pathBlackList</key>
<array>
<string>/path/to/an.app</string>
<string>/path/to/asecond.app</string>
</array>
to control which apps to block.
Save the following to a file with the extension .mobileconfig
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PayloadIdentifier</key>
<string>com.company.macos.blockapps</string>
<key>PayloadRemovalDisallowed</key>
<true/>
<key>PayloadScope</key>
<string>System</string>
<key>PayloadType</key>
<string>Configuration</string>
<key>PayloadUUID</key>
<string>9c24d6b3-6233-4a08-a48d-9068f4f76cf0</string>
<key>PayloadOrganization</key>
<string>Company Name</string>
<key>PayloadVersion</key>
<integer>1</integer>
<key>PayloadDisplayName</key>
<string>Block Apps In User Folder</string>
<key>PayloadContent</key>
<array>
<dict>
<key>PayloadType</key>
<string>com.apple.applicationaccess.new</string>
<key>PayloadVersion</key>
<integer>1</integer>
<key>PayloadIdentifier</key>
<string>MCXToProfile.9c24d6b3-6233-4a08-a48d-9068f4f76cf0.alacarte.customsettings.2476221c-1870-4f3e-8c52-52386029c4cf</string>
<key>PayloadEnabled</key>
<true/>
<key>PayloadUUID</key>
<string>2476221c-1870-4f3e-8c52-52386029c4cf</string>
<key>PayloadDisplayName</key>
<string>Blocks all apps in the ~/ directory./string>
<key>familyControlsEnabled</key>
<true/>
<key>pathBlackList</key>
<array>
<string>/path/to/an.app</string>
<string>/path/to/asecond.app</string>
</array>
</dict>
</array>
</dict>
</plist>
Create the LaunchDaemon
Note: You must be an admin to do this.
Save the following file to /Library/LaunchDaemons/
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.PlzUpvoteMy.answer</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/open</string>
<string>-W</string>
<string>**/path/to/application.app**</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StartCalendarInterval</key>
<!--- Creds to @Allan for Calendar Interval -->
<!-- Weekdays are 1 - 5; Sunday is 0 and 7 -->
<array>
<dict>
<key>Weekday</key>
<integer>5</integer>
<key>Hour</key>
<integer>12</integer>
<key>Minute</key>
<integer>01</integer>
</dict>
<dict>
<key>Weekday</key>
<integer>6</integer>
<key>Hour</key>
<integer>00</integer>
<key>Minute</key>
<integer>00</integer>
</dict>
</array>
<key>UserName</key>
<string>**UserToBlock**</string>
</dict>
</plist>
Change the permissions with the following command:
sudo chown root:wheel /Library/LaunchDaemons/com.MyName.plist
Load the Daemon
Note: You must be admin to do this.
To start the daemon use this command:
sudo launchctl load /Library/LaunchDaemons/com.MyName.plist
The program will scan for the apps every 5 seconds and close them if they are running.
To stop the Daemon use this command
sudo launchctl unload /Library/LaunchDaemons/com.MyName.plist
Applaud Yourself
- Applaud yourself