Skip to content

Instantly share code, notes, and snippets.

@ksylvan
Last active October 10, 2017 13:52
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ksylvan/2aacf2b466741a5468b2ea7ab475ee97 to your computer and use it in GitHub Desktop.
Save ksylvan/2aacf2b466741a5468b2ea7ab475ee97 to your computer and use it in GitHub Desktop.
Ansible playbook for fixing up a Mac Dock using dockutil
# Based on https://blog.vandenbrand.org/2016/01/04/how-to-automate-your-mac-os-x-setup-with-ansible/
#
- hosts: all
tasks:
- name: Current Dock names
shell: >
dockutil --list |
python -c 'import sys; [sys.stdout.write(line.split("\t")[0] + "\n")
for line in sys.stdin]'
register: dockitems
changed_when: false
- set_fact:
x: '{{ dockitems_to_remove | intersect(dockitems.stdout_lines) }}'
- name: Remove Dock items
shell: dockutil --remove '{{ item }}'
with_items: '{{ x }}'
- set_fact: y='{{ dockitems_to_persist|map(attribute="name")|list }}'
- set_fact:
x: '{{ y | difference(dockitems.stdout_lines) }}'
- name: Add Dock items
shell: >
dockutil --find '{{ item.name }}' ||
dockutil --add '{{ item.path }}'
with_items: '{{ dockitems_to_persist }}'
when: '{{ x != [] }}'
#
# dockutil is installed via brew
#
# Variables needed look like this:
#
# dockitems_to_remove:
# - Launchpad
# - Contacts
# - Notes
# - Reminders
# - Maps
# - Pages
# - Photos
# - FaceTime
# - iBooks
# - App Store
# - System Preferences
#
# dockitems_to_persist:
# - name: VirtualBox
# path: /Applications/VirtualBox.app
# - name: Terminal
# path: /Applications/Utilities/Terminal.app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment