The Problem

I was just thinking about my signal-to-noise ratio during coding and I noticed that my OS X dock has lots of stuff in it. I like this stuff. I want to keep this stuff. Also I hate a dock that hides. But I thought this: it would be nice to have an icon to click on that switches the dock between “only show running apps”-mode and normal mode.

dockfocus.py

It turns out that this is easy because some awesome apple employee hid this function in the dock. I just need a little script that toggles the state and restarts the dock. Here’s that little script:

#!/usr/bin/python
""" Toggles com.apple.dock static-only, then restarts the dock """
import subprocess
    
    
def dock_is_focused():
    """ Return true if the dock is in static-only mode """
    try:
        mode = subprocess.check_output(
            "defaults read com.apple.dock static-only".split(),
            stderr=subprocess.STDOUT)
    except subprocess.CalledProcessError, exception:
        if exception.returncode == 1 and "does not exist" in exception.output:
            return False
        raise
    
    if "1" in mode or "t" in mode or "T" in mode:
        return True
    
    return False
    
    
def focus_dock():
    """ Sets com.apple.dock static-only to true """
    subprocess.check_call(
        "defaults write com.apple.dock static-only -bool true".split())
    
    
def unfocus_dock():
    """ Sets com.apple.dock static-only to false """
    subprocess.check_call(
        "defaults delete com.apple.dock static-only".split())
    
    
def restart_dock():
    """ Runs osascript to restart the Dock the applescript way """
    subprocess.check_call(["osascript",
                           "-e", 'tell application "Dock"',
                           "-e", "quit",
                           "-e", "end tell"])
    
    
if __name__ == "__main__":
    if dock_is_focused():
        unfocus_dock()
    else:
        focus_dock()
    restart_dock()

DockFocus.app

The final part of the solution is an app to click on. I whipped out the ever-useful always-underrated Platypus, fed it dockfocus.py, “made” a crappy icon1, and voilà!

DockFocus.app Icon

DockFocus.dmg (click the icon to download)

  • Contains DockFocus.app
  • The License is BSD-like
  • This software come with no warranty at all

Unnecessary DockFocus.app User Manual

Installing It

  • Download and open the above DMG
  • Copy the app from the DMG to your applications folder or your desktop
  • The app isn’t signed, so if you have GateKeeper turned on (as you should), you will want to right-click the app the first time and select “Open”, then click the “Open” button. (from then on it will work normally – if you have trouble with this, check out that GateKeeper link)

Using It

  • Every time you run the app it will switch the dock between “focused” where only running apps are showing and “unfocused” where all apps show

Uninstalling It

  • To uninstall the app just drag it to the trash
  • If you deleted the app while your dock was “focused” then you can just download it again, and run it one more time. If you don’t want to do that, you can also copy-and-paste this directly into the terminal to get things back to normal: defaults delete com.apple.dock static-only

  1. icon mostly “inspired by” by Apple’s dock icon [return]