Estaba tratando de lograr esto usando una segunda cuenta (que es la cuenta de administrador) y Controles parentales, pero parecía que no era posible hacerlo.
Sé que hay algunos programas que puedes descargar que te ayudan con esto (Cold Turkey, por ejemplo). Pero sería mucho más fácil si pudiera hacer esto usando solo las herramientas que ya están disponibles en macOS.
Puede hacer esto con dos herramientas integradas:
Usando Gatekeeper, podemos crear "reglas" que le permitan bloquear/habilitar aplicaciones. Usando su ejemplo, podemos crear una lista de aplicaciones que solo pueden ejecutarse los viernes:
spctl --add --label "FridayApps" /Applications/SomeApp.app
El beneficio de esto es que puede agregar múltiples aplicaciones con la misma etiqueta y habilitarlas/deshabilitarlas con un solo comando:
sudo spctl --disable --label "FridayApps" <---- For Saturday thru Thursday
sudo spctl --enable --label "FridayApps" <---- For Friday
Para esto, necesitará un script simple para habilitar/deshabilitar las aplicaciones y debe ejecutarlo como un demonio (necesita sudo
privilegios), por lo que debe residir en /Library/LaunchDaemons
.
Usé la convención de nomenclatura com.user.FridayApps.plist
y FridayApp.sh
para el guión.
Guión de bash:
#!/bin/bash
DOW=$(date +%u) # Sets the Day of Week; 5 = Friday
TOD=$(date +%T) # Sets the time of Day
start="12:00:00" # Sets start time
end="23:59:00" # Sets end time
if [ $DOW -eq 5 ]
then
if [[ "$TOD" > "${start}" && "$TOD" < "${end}" ]]
then
/usr/sbin/spctl --enable --label "FridayApps"
fi
else
/usr/sbin/spctl --disable --label "FridayApps"
fi
lanzado.plist
<?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.user.FridayApps</string>
<key>ProgramArguments</key>
<array>
<string>/User/MyName/script/location/FridayApps.sh</string>
</array>
<key>StartCalendarInterval</key>
<!-- 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>
</dict>
<key>RunAtLoad</key>
<true/>
</plist>
##Load the `.plist`
sudo launchctl load com.user.FridayApps.plist
Lo que está pasando aquí son dos cosas:
launchd
está ejecutando un script dos veces. Una vez para encenderlo y otra vez para apagarlospctl -a /Applications/AppName.app
le dirá si está habilitado o deshabilitado. Escribí un script de notificación basado en el contexto de un archivo de texto; no es demasiado difícil de modificar para esta aplicación: apple.stackexchange.com/q/257541/119271En el siguiente tutorial harás lo siguiente:
Abra esto en el Editor de secuencias de comandos y expórtelo como una aplicación de solo lectura y asegúrese de permanecer abierto después de que el controlador de ejecución no esté activado.
Después de exportar, siga esta guía para evitar que aparezca en el muelle.
# 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
Usar
<key>pathBlackList</key>
<array>
<string>/path/to/an.app</string>
<string>/path/to/asecond.app</string>
</array>
para controlar qué aplicaciones bloquear.
Guarde lo siguiente en un archivo con la extensión.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>
Nota: Debe ser administrador para hacer esto.
Guarde el siguiente archivo en/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>
Cambie los permisos con el siguiente comando:
sudo chown root:wheel /Library/LaunchDaemons/com.MyName.plist
Nota: Debe ser administrador para hacer esto.
Para iniciar el daemon use este comando:
sudo launchctl load /Library/LaunchDaemons/com.MyName.plist
El programa buscará las aplicaciones cada 5 segundos y las cerrará si se están ejecutando.
Para detener el Daemon usa este comando
sudo launchctl unload /Library/LaunchDaemons/com.MyName.plist
JBis
John Smith
JBis