Code Monkey home page Code Monkey logo

docklib's Introduction

docklib

This is a Python module intended to assist IT administrators with manipulation of the macOS Dock.

Originally created as a Gist by @gregneagle and modified to include support for spacers by @discentem.

Installation

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.

Examples

Add Microsoft Word to the right side of the Dock

from docklib import Dock
dock = 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 Dock

from docklib import Dock
dock = 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 Dock

from docklib import Dock
dock = Dock()
dock.replaceDockEntry('/Applications/Microsoft Outlook.app', 'Mail')
dock.save()

Remove Calendar from the Dock

from docklib import Dock
dock = Dock()
dock.removeDockEntry('Calendar')
dock.save()

Display the current orientation of the Dock

from docklib import Dock
dock = Dock()
print dock.orientation

Make the Dock display on the left, and enable autohide

from docklib import Dock
dock = Dock()
dock.orientation = 'left'
dock.autohide = True
dock.save()

Add the Documents folder to the right side of the Dock

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()

Specify a custom Dock for the local IT technician account

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()

docklib's People

Contributors

homebysix avatar discentem avatar neilmartin83 avatar wardsparadox avatar

Watchers

Henry Stamerjohann avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.