I find it helpful to be able to automate this app, so that I don't change my mind and decide to blow off work at the beginning of the day. To this end I have an AppleScript scheduled to activate SelfControl every weekday morning while I'm still sleeping, which lasts until mid-day, so I can get stuff done when I wake up, rather than just roll out of bed onto Facebook.
Prerequisites:
- Naturally, you'll need SelfControl.
- You'll also need to download and install Daniel Jalkut's Usable Keychain Scripting to quickly and securely access your admin password in order to activate SelfControl. As of this writing, OS X's current Keychain Scripting is rather slow.
- Open Keychain Access. Create a new password by typing Cmd-N or going to File » New Password Item...
- Under Keychain Item Name, type 'SelfControl.' Make up any Account Name in the next field, and in the Password field, type the password for your user account (the password you would use to authenticate anything in OS X). Click 'Add', and you should now have a new application password entitled 'SelfControl' in your Keychain.
- Open AppleScript Editor and paste in the following code:
on run argv set defaultTime to 1 try set myTime to item 1 of argv as number on error set myTime to defaultTime end try tell application "Usable Keychain Scripting" tell current keychain set myPass to (password of first generic item ¬ whose name contains "SelfControl") -- eliminate invisible characters, or "gremlins," from password set x to quoted form of myPass set myPass to do shell script "echo " & x & " | perl -pe 's/[^[:print:]]//g'" end tell end tell tell application "SelfControl" to activate tell application "System Events" tell process "SelfControl" tell slider of window "SelfControl" to set value to myTime click button "Start" of window "SelfControl" end tell tell window 1 of process "SecurityAgent" with timeout of 15 seconds repeat set tryAgain to false try set value of text field 2 of scroll area 1 of group 1 to myPass on error delay 1 set tryAgain to true end try if not tryAgain then exit repeat end repeat click button 2 of group 2 end timeout end tell end tell end run
- Run the script once; you will be prompted to allow Usable Keychain Scripting to access your keychain. Click 'Always Allow.' Note: This will activate SelfControl for 1 minute, so don't navigate away from this page during that time!
- In your script, at the line that says defaultTime to 1, change 1 to 45 (or whatever number of minutes you'd like the default time to be.) I use 45, so that I can run this script hourly: work 45 minutes, play for 15. Now save the script and name it something like selfcontrol.scpt.
The script can also be run with arguments from the command line to achieve different timings. I like to have SelfControl automatically run from 7-10am every weekday morning, so my crontab has the following line in it:
0 7 * * 1,2,3,4,5 osascript /Applications/kerfi/Applescript/selfcontrol.scpt 180
[crarko adds: I haven't tested this one, although I can think of a number of applications for it.]