Created
January 1, 2021 20:52
-
-
Save tjluoma/202526420d4b82eb4d078dd4a7380c84 to your computer and use it in GitHub Desktop.
This AppleScript will lock your Mac at 5pm and midnight [see installation info below]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>Disabled</key> | |
<false/> | |
<key>Label</key> | |
<string>com.tjluoma.lockscreen</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/usr/bin/osascript</string> | |
<string>-e</string> | |
<string>tell application "System Events"</string> | |
<string>-e</string> | |
<string>keystroke "q" using {control down, command down}</string> | |
<string>-e</string> | |
<string>end tell</string> | |
</array> | |
<key>RunAtLoad</key> | |
<false/> | |
<key>StandardErrorPath</key> | |
<string>/tmp/com.tjluoma.lockscreen.log</string> | |
<key>StandardOutPath</key> | |
<string>/tmp/com.tjluoma.lockscreen.log</string> | |
<key>StartCalendarInterval</key> | |
<array> | |
<dict> | |
<key>Hour</key> | |
<integer>0</integer> | |
<key>Minute</key> | |
<integer>0</integer> | |
</dict> | |
<dict> | |
<key>Hour</key> | |
<integer>17</integer> | |
<key>Minute</key> | |
<integer>0</integer> | |
</dict> | |
</array> | |
</dict> | |
</plist> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(Optional) Edit the plist to change the times when your Mac will be locked. "Hour 0" is midnight. "Hour 17" is 5 p.m. You can adjust those at will.¹
Save this to ~/Library/LaunchAgents/com.tjluoma.lockscreen.plist
Add
/usr/bin/osascript
to System Preferences » Security & Privacy » Privacy » Accessibility (click on the+
and then nagivate to/usr/bin/osascript
so it appears in the list. Make sure it is ✔️ checked.¹ Use LaunchControl to avoid having to edit
launchd
plists by hand.⌘⌃Q
was added as globalLock Screen
command