Automatic social discipline
I lack self-control and waste far too much time on social apps on my computer, especially Twitter, and more recently, Slack. Here’s a typical weekly breakdown as reported to me by the very good RescueTime:
I could just uninstall them or block their services at the network level, but I need both of them for parts of my work — I just don’t need to keep switching over to them constantly and wasting so many hours per week. Without any intervention, I’ll just habitually leave these apps open, right next to what I’m working on, resulting in a steady stream of tiny interruptions throughout the day as new messages trickle in.
Tonight, I hacked together yet another crazy idea to try to mitigate these problems: a script that automatically quits social and news apps every 10 minutes unless I’m actively using them, or if I’m podcasting (in which case I want them to stay open even if they’re not in the foreground).
Here’s how to do this, if you’re interested:
Open Script Editor and save this as an AppleScript somewhere (I saved it as ~/antisocial.scpt
):
set quitlist to {"Tweetbot"}
set exceptionTriggerList to {"Skype"}
tell application "System Events"
set activeAppName to name of the first process whose frontmost is true
end tell
set exceptionRunning to false
repeat with exceptionName in exceptionTriggerList
if exceptionRunning is false and application exceptionName is running then
set exceptionRunning to true
end if
end repeat
if exceptionRunning is false then
repeat with appName in quitlist
if (activeAppName as string) is not (appName as string) and application appName is running then
tell application appName to quit
end if
end repeat
end if
My lists on top there mean, “Quit Tweetbot, Slack, and ReadKit if they are not the active application, but only if Skype isn’t open.” Adjust as necessary.
Then you’ll need launchd
to run it at your desired time interval. Create a com.marcorules.antisocial.plist
file in ~/Library/LaunchAgents
that points to the AppleScript like this:
<?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>EnableGlobbing</key>
<false/>
<key>Label</key>
<string>com.marcorules.antisocial</string>
<key>LowPriorityIO</key>
<false/>
<key>Nice</key>
<integer>0</integer>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/osascript</string>
<string>/Users/YOURUSERNAMEHERE/antisocial.scpt</string>
</array>
<key>StartInterval</key>
<integer>600</integer>
</dict>
</plist>
Change the YOURUSERNAMEHERE
bit to point to where you saved that AppleScript, and set the StartInterval
integer to your desired time interval in seconds (600 = 10 minutes).
Then run this in Terminal to add this new task to launchd
:
launchctl load ~/Library/LaunchAgents/com.marcorules.antisocial.plist
You can test it by opening any of the targeted apps, then running this in Terminal:
launchctl start com.plisterine.antisocial
…or just waiting 10 minutes.
I don’t know if this will stick, or if it’ll meaningfully solve my problem, but it’s worth a try.