Package: docklib
docklibThis is a Python module intended to assist IT administrators with manipulation of the macOS Dock.Originally created as aGistby @gregneagle, this fork has been modified to include support for some additional Dock features, and has been packaged for multiple distribution options.InstallationThere are multiple methods of installing docklib, depending on how you plan to use it.Package installerYou can use the includedbuild_pkg.shscript to build a macOS installer .pkg file. You can use this package to install docklib on your own Mac, or deploy the package using a tool like Jamf or Munki to install docklib on managed devices.To run the script,cdto a local clone of this repository, then run:./build_pkg.shThe resulting pkg will be built in a temporary folder and shown in the Finder.NOTE: The default install destination is/Library/Python/2.7/site-packages/docklib, which makes docklib available to the built-in macOS Python 2.7 framework. If you leverage a different Python installation, you'll need to modify this path in thebuild_pkg.shscript prior to building the installer package.PipDocklib has been published to PyPI in order to make it available for installation using pip.pip install docklibThis method is not intended to be used directly on managed devices, but it could be leveraged alongside a custom Python framework (like one built withmacadmins/pythonorrelocatable-python) using a requirements file.Managed PythonDocklib is included in the "recommended" flavor of themacadmins/pythonrelease package. Installing this package and using#!/usr/local/managed_python3for your docklib script shebang may be the most self-contained and future-proof way to deploy docklib.ManualAnother method of using docklib is to simply place the docklib.py file in the same location as the Python script(s) you use to manipulate the macOS dock. Some examples of such scripts are included below.ExamplesAdd Microsoft Word to the right side of the DockfromdocklibimportDockdock=Dock()item=dock.makeDockAppEntry("/Applications/Microsoft Word.app")dock.items["persistent-apps"].append(item)dock.save()Add Microsoft Word to the left side of the DockfromdocklibimportDockdock=Dock()item=dock.makeDockAppEntry("/Applications/Microsoft Word.app")dock.items["persistent-apps"]=[item]+dock.items["persistent-apps"]dock.save()Replace Mail.app with Outlook in the DockfromdocklibimportDockdock=Dock()dock.replaceDockEntry("/Applications/Microsoft Outlook.app","Mail")dock.save()Remove Calendar from the DockfromdocklibimportDockdock=Dock()dock.removeDockEntry("Calendar")dock.save()Display the current orientation of the DockfromdocklibimportDockdock=Dock()printdock.orientationMake the Dock display on the left, and enable autohidefromdocklibimportDockdock=Dock()dock.orientation="left"dock.autohide=Truedock.save()Add the Documents folder to the right side of the DockDisplays 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.importosfromdocklibimportDockdock=Dock()ifdock.findExistingEntry("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()Add a URL to the right side of the DockDisplays 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.importosfromdocklibimportDockdock=Dock()ifdock.findExistingEntry("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()Specify a custom Dock for the local IT technician accountimportosfromdocklibimportDocktech_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"]=[]foritemintech_dock:ifos.path.exists(item):item=dock.makeDockAppEntry(item)dock.items["persistent-apps"].append(item)dock.save()Or if you prefer using alist comprehension:importosfromdocklibimportDocktech_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"]=[dock.makeDockAppEntry(item)foritemintech_dockifos.path.exists(item)]dock.save()