如何让 SelfControl 始终运行?

Mar*_*ark 8 selfcontrol macos

我使用 SelfControl 应用程序。

有没有办法让它一直运行?

Sco*_*ott 7

是的。只需从/Applications文件夹中打开“系统偏好设置”,选择“帐户”,然后在左侧列表中突出显示您的用户名,然后选择“登录项目”选项卡。将 SelfControl 拖放到列表中,或单击“+”按钮并导航到其位置。

然后,SelfControl 将始终在您登录时启动。


您需要下载并安装 Daniel Jalkut 的可用钥匙串脚本,以便快速安全地访问您的管理员密码以激活 SelfControl。

给钥匙串添加密码

打开钥匙串 Access.app。通过键入 Cmd-N 或转到文件»新密码项...创建新密码,在钥匙串项名称下,键入“SelfControl”。在下一个字段中输入任何帐户名称,然后在密码字段中,键入您的用户帐户的密码(在 OS X 中用于验证任何内容的密码)。单击“添加”,您的钥匙串中现在应该有一个名为“SelfControl”的新应用程序密码。

创建 AppleScript

将以下内容(最初来自此处)粘贴到AppleScript Editor.app的新窗口中:

on run argv
 set defaultTime to 1440

 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 Code Online (Sandbox Code Playgroud)

我们defaultTime在此处设置为 1440(即 24 小时),以便您可以在最长时间内自动启动 SelfControl。

现在,从 AppleScript 编辑器中,通过按File » Save将该文件保存在某个位置,例如/Users/your-username/SelfControl.scpt,它位于我们的主文件夹中。记住那条路。

创建launchd条目

然后打开您最喜欢的文本编辑器或属性列表 Editor.app,它随附在 Snow Leopard 上的 Mac OS X 开发工具或已集成到 Lion 上的 Xcode 中。

无论哪种方式,粘贴以下内容,但请确保相应地更改脚本的路径(它不是我们上面记住的路径):

<?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>my.selfcontrol.launcher</string>
    <key>ProgramArguments</key>
    <array>
        <string>osascript</string>
        <string>/Users/your-username/SelfControl.scpt</string>
    </array>
    <key>StartInterval</key>
    <integer>86400</integer>
    <key>RunAtLoad</key>
    <false/>
    <key>KeepAlive</key>
    <false/>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud)

使用.plist扩展名保存此文件/Users/your-username/Library/LaunchAgents/my.selfcontrol.launcher.plist。如果 Library 文件夹被隐藏,您可以打开 Finder,按CmdShiftG并粘贴~/Library打开它。

加载launchd条目

最后,打开终端并运行:

launchctl load ~/Library/LaunchAgents/my.selfcontrol.launcher.plist
Run Code Online (Sandbox Code Playgroud)

这将告诉launchd每二十四小时打开AppleScript并启动SelfControl 24小时。

因为它在~/Library/LaunchAgents里面,当你登录时它会自动加载。如果你想让你的电脑回来,load把上面的命令替换为unload,然后等待剩余的 SelfControl 时间到期。

  • 在那种情况下,我将谴责人们在不解释的情况下投票! (2认同)

小智 7

您可以轻松地在任何时间段内制作 SelfControl 块——尽管我们不提供“无限”设置,但我认为长达一年的块可以实现大部分相同的目的。然后你可以随时重新启动它。要阻止长达一年,首先关闭 SelfControl,然后打开终端并运行以下命令:

defaults write org.eyebeam.SelfControl MaxBlockLength -int 31556900
defaults write org.eyebeam.SelfControl BlockLengthInterval -int 432000
Run Code Online (Sandbox Code Playgroud)

重新打开 SelfControl,滑块将一直运行到一年(间隔 5 天)。你可以用任何块长度和间隔来做这个技巧,尽管我们的显示目前不显示年——它可能会以天或周为单位显示该长度。

有关更多信息,请参阅我们 wiki 上的这篇文章。但是请注意,如果您在终端中搞砸了计算机,我们将无法提供支持,因此这仅适用于专业用户。有关此类调整的更多信息最终将在我们的新网站上提供


And*_*eas 5

这里有一个小实用程序,可以帮助安排 SelfControl: https://github.com/andreasgrill/auto-selfcontrol 有了这个,您可以轻松创建一个计划,每天从上午 12 点到晚上 11 点 59 分运行。该实用程序直接使用 SelfControl 的命令行 API,不需要将管理员密码存储在文件中。