Hier ist das Paket, das ich erstellt habe, um Anwendungen im Dock der von uns eingesetzten MacOS-Workstations hinzuzufügen und zu entfernen.
Es lässt sich durch Bearbeiten der Tabellen leicht modifizieren zu_entfernen[] Und to_add[] wann immer es Ihnen passt.
Es verwaltet nur Anwendungen, die sich im Verzeichnis /Applications/ befinden (dies lässt sich bei Bedarf aber problemlos ändern).
Sie können auch nur die Funktionen fortsetzen Dock-Abkürzung entfernen() Und add_dock_shortcut() und verwenden Sie sie in Ihren Paketen.
Es ist nicht super sauber, aber es erfüllt seinen Zweck; wenn Sie ein besseres haben, bin ich ganz Ohr
Code: Alle auswählen
# -*- coding: utf-8 -*-
from setuphelpers import *
# Source: https://stackoverflow.com/questions/19918547/how-to-remove-an-application-icon-from-dock-from-mac-osx-mavericks
def install():
print(r'Installation does nothing, dock will be configured per user at first session-setup.')
def uninstall():
print(r'Uninstallation does nothing, launch "defaults delete com.apple.dock; killall Dock" in user shell to reset the dock to defaults settings.')
def session_setup():
to_remove = ["Safari", "Messages", "Mail", "Plans", "Photos", "FaceTime", "Contacts", "Freeform", "TV", "Musique", "Keynote", "Numbers", "Pages", "App Store"]
for app in to_remove:
remove_dock_shortcut(name=app)
to_add = ["Thunderbird", "3CX Desktop App", "Spark", "WAPT/WAPT Self-service"]
for app in to_add:
add_dock_shortcut(name=app)
# Reload dock after all modifications
run("osascript -e 'tell Application \"Dock\"' -e 'quit' -e 'end tell'")
def remove_dock_shortcut(name=None, reload=False):
"""Remove shortcut from MacOS dock
Args:
name : application name (it has to be in /Application/)
reload (boolean) : if True, reload dock before return
Returns:
True if dock was updated, else False
"""
if name:
all_shortcuts = run(r'defaults read com.apple.dock persistent-apps | grep file-label\"').split("\n")
i = 0
for shortcut in all_shortcuts:
if "=" in shortcut:
current = shortcut.split("=")[1].split(";")[0].strip().strip('"')
if current == name:
run(r'/usr/libexec/PlistBuddy -c "Delete persistent-apps:%s" ~/Library/Preferences/com.apple.dock.plist' % i)
if reload:
run("osascript -e 'tell Application \"Dock\"' -e 'quit' -e 'end tell'")
return True
i += 1
return False
def add_dock_shortcut(name=None, reload=False):
"""Add shortcut to MacOS dock
Args:
name : application name (it has to be in /Application/)
reload (boolean) : if True, reload dock before return
Returns:
True if dock was updated, else False
"""
if name:
run(r'defaults write com.apple.dock persistent-apps -array-add "<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>/Applications/%s.app/</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>"' % name)
if reload:
run("osascript -e 'tell Application \"Dock\"' -e 'quit' -e 'end tell'")
return True
return False