I have an AppleScript that automatically opens SelfControl.app to help avoid distractions when I want to be working. The script is very similar to automate an Internet content filter, and it is automatically launched by iCal at a set time.

The problem is that when the script runs, the window opens on the screen, and if I'm in the middle of typing something, then my typing interferes with the dialog box for entering the password, and the script fails.

How can I get the script to run independently from the user's activity? In other words, how can I run the script without showing the user the GUI evidence that the script is running?


Below is a snippet of code. myTime and myPass are defined earlier in the script:

set myTime to …
set myPass to …

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
                set tryAgain to false
                    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
  • Are you running the script directly from iCal? You could try to wrap it in an automator "programm".
    – nfechner
    Aug 24, 2015 at 9:28
  • Any chance you could give us a code snippet? If the dialog box is coming from a "do shell script", you can manually specify the password parameter like so (which will prevent the dialog box from showing): do shell script "stuff do to" password "secret password" with administrator privileges Aug 24, 2015 at 11:43
  • @nfechner It is being run by an automator ".app" file. Aug 24, 2015 at 13:29
  • @WilliamTFroggard I added some code to the question. Any ideas? Aug 24, 2015 at 13:30

2 Answers 2


This can be achieved from the command line using the defaults system, as demonstrated at the SelfControl github site.

To avoid link-rot, I copy the site's text below:

In some cases, you may want to start a SelfControl block from the command line. This can make it much easier for advanced users to script their SelfControl blocks. This article explains how you can start SelfControl from the command line. If you're not familiar with the command line, this article is not for you.

  • Install SelfControl into your Applications folder.
  • Set your block preferences via the defaults system. The key values you'll need to set are BlockDuration (length of the block in minutes), HostBlacklist (an array containing the list of hosts to block/whitelist), and BlockAsWhitelist (makes it a whitelist instead of blacklist). There are more preferences if you want them; you can see them by running defaults read org.eyebeam.SelfControl (or just configure them in the app's preferences panel). Don't set BlockStartedDate, that's handled by the program automatically.
  • Run sudo /Applications/SelfControl.app/Contents/MacOS/org.eyebeam.SelfControl $(id -u $(whoami)) --install to start a block. It will automatically run checkups to see if the block needs removal every minute.
  • Wait for the block to expire. If you want to manually run a checkup to remove the block if necessary, you can do so with sudo /Library/PrivilegedHelperTools/org.eyebeam.SelfControl $(id -u $(whoami)) --checkup. If that doesn't remove the backup successfully, you can run our backup removal tool with /Library/PrivilegedHelperTools/scheckup.

You can try launching "SelfControl" in the background, then hiding it (although, simply launching in the background may be enough in your case). The idea is to hide the application once a window appears, indicating the launch process is mostly done, and the application can be hidden (which takes a few seconds. I generally shy away from using arbitrary delays for this kind of thing):

tell application "SelfControl"
    repeat while (window 1 exists) is false
        delay 0.5
    end repeat
end tell
tell application "System Events"
    tell process "SelfControl"
        set visible to false
    end tell
end tell

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .