-
Notifications
You must be signed in to change notification settings - Fork 17
Home
This is a Python module intended to assist IT administrators with manipulation of the macOS Dock.
Originally created as a Gist by @gregneagle, this fork has been modified to include support for some additional Dock features.
Place the docklib.py file in your Python path so its contents can be imported into scripts you create. Or, include the file in the same directory as your script.
The packages available in the Releases section will place the docklib.py file into /Library/Python/2.7/site-packages.
from docklib import Dock
dock = Dock()
item = dock.makeDockAppEntry("/Applications/Microsoft Word.app")
dock.items["persistent-apps"].append(item)
dock.save()
from docklib import Dock
dock = Dock()
item = dock.makeDockAppEntry("/Applications/Microsoft Word.app")
dock.items["persistent-apps"] = [item] + dock.items["persistent-apps"]
dock.save()
from docklib import Dock
dock = Dock()
dock.replaceDockEntry("/Applications/Microsoft Outlook.app", "Mail")
dock.save()
from docklib import Dock
dock = Dock()
dock.removeDockEntry("Calendar")
dock.save()
from docklib import Dock
dock = Dock()
print dock.orientation
from docklib import Dock
dock = Dock()
dock.orientation = "left"
dock.autohide = True
dock.save()
Displays as a stack to the right of the Dock divider, sorted by modification date, that expands into a fan when clicked. This example checks for the existence of the Documents item and only adds it if it's not already present.
import os
from docklib import Dock
dock = Dock()
if dock.findExistingLabel("Documents", section="persistent-others") == -1:
item = dock.makeDockOtherEntry(
os.path.expanduser("~/Documents"), arrangement=3, displayas=1, showas=1
)
dock.items["persistent-others"] = [item] + dock.items["persistent-others"]
dock.save()
Displays as a globe to the right of the Dock divider, that launches a URL in the default browser when clicked. This example checks for the existence of the Documents item and only adds it if it's not already present.
import os
from docklib import Dock
dock = Dock()
if dock.findExistingLabel("GitHub", section="persistent-others") == -1:
item = dock.makeDockOtherURLEntry("https://www.github.com/", label="GitHub")
dock.items["persistent-others"] = [item] + dock.items["persistent-others"]
dock.save()
import os
from docklib import Dock
tech_dock = [
"/Applications/Google Chrome.app",
"/Applications/App Store.app",
"/Applications/Managed Software Center.app",
"/Applications/System Preferences.app",
"/Applications/Utilities/Activity Monitor.app",
"/Applications/Utilities/Console.app",
"/Applications/Utilities/Disk Utility.app",
"/Applications/Utilities/Migration Assistant.app",
"/Applications/Utilities/Terminal.app",
]
dock = Dock()
dock.items["persistent-apps"] = []
for item in tech_dock:
if os.path.exists(item):
item = dock.makeDockAppEntry(item)
dock.items["persistent-apps"].append(item)
dock.save()