A Python application that automatically logs out your macOS user after a specified duration.
- ✅ Flexible time format support (seconds, minutes, hours)
- ✅ Configuration file support for saving settings
- ✅ Graceful interrupt handling (Ctrl+C to cancel)
- ✅ Cross-method logout handling
- ✅ Clear user feedback and status messages
- macOS 10.13+
- Python 3.7+
- Clone or download the repository:
cd /Users/tylerburton/Repos/mac-timer- Make the script executable:
chmod +x mac_timer.pyLogout in 30 seconds:
python3 mac_timer.py 30sLogout in 5 minutes:
python3 mac_timer.py 5mLogout in 2 hours:
python3 mac_timer.py 2hLogout in 1 hour 30 minutes:
python3 mac_timer.py 1h30mLogout in 3600 seconds (plain number):
python3 mac_timer.py 3600Save configuration and start timer:
python3 mac_timer.py -c ~/.mac-timer/config.json 5mLoad and use saved configuration:
python3 mac_timer.py -l -c ~/.mac-timer/config.jsonThe duration argument supports multiple formats:
- Seconds:
30sor just30 - Minutes:
5m - Hours:
2h - Combined:
1h30m,2h15m30s
To automatically start the timer at login, you can create a LaunchAgent:
- Create the directory if it doesn't exist:
mkdir -p ~/Library/LaunchAgents- Create the plist file:
cat > ~/Library/LaunchAgents/com.local.mactimer.plist << 'EOF'
<?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.local.mactimer</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/python3</string>
<string>/Users/tylerburton/Repos/mac-timer/mac_timer.py</string>
<string>2h</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardOutPath</key>
<string>/tmp/mactimer.log</string>
<key>StandardErrorPath</key>
<string>/tmp/mactimer.err</string>
</dict>
</plist>
EOF- Load the agent:
launchctl load ~/Library/LaunchAgents/com.local.mactimer.plistTo unload:
launchctl unload ~/Library/LaunchAgents/com.local.mactimer.plist- This application uses
osascriptto trigger logout, which requires user interaction/confirmation in some cases - Alternative method using
loginwindowmay require elevated privileges - The script can be interrupted at any time with Ctrl+C
- Try running with
sudoif you have permission issues - Ensure you're running on macOS 10.13 or later
- The app needs to be running in the foreground or background
- Consider using LaunchAgent for background execution
MIT License