Skip to content

Instantly share code, notes, and snippets.

@BJTerry
Created May 16, 2013 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BJTerry/5593180 to your computer and use it in GitHub Desktop.
Save BJTerry/5593180 to your computer and use it in GitHub Desktop.
A modification of the script at http://hints.macworld.com/article.php?story=20100801214648362 to prompt for a delay and minutes of control. If you want to set your own defaults, change the 180 or the 30 to whatever amount you want.
on run argv
set defaultTime to 1
try
set myTime to item 1 of argv as number
set myDelay to 0
on error
display dialog "Enter time to block in minutes" default answer 180
set myTime to (text returned of result) as number
display dialog "After how much time" default answer 30
set myDelay to (text returned of result) as number
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
delay (myDelay * 60)
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment