Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Single script to set the dock for multiple users
#!/usr/bin/python
#----------AUTHOR------------
# Jacob Salmela
# 3 January 2014
#-----------IMPORTS----------
from subprocess import call
from platform import mac_ver
from re import findall
from socket import gethostname
from os import path
from os import chown
from os import system
from pwd import getpwnam
from shutil import copyfile
#----------VARIABLES---------
osx_version = mac_ver()[0]
computer_name = gethostname().split('-')
mavericks = findall('10.9.*', osx_version)
mountain_lion = findall('10.8.*', osx_version)
lion = findall('10.7.*', osx_version)
snow_leopard = findall('10.6.*', osx_version)
admin_user = "/Users/admin"
student_user = "/Users/student"
testing_user = "/Users/testing"
all_user_apps = ["/Applications/Safari.app",
"/Applications/Firefox.app",
"/Applications/Google Chrome.app"
]
admin_apps = ["/Applications/Utilities/Console.app",
"/Applications/Utilities/Disk Utility.app",
"/Applications/Utilities/Terminal.app",
"/Applications/System Preferences.app",
"/Applications/Utilities/Activity Monitor.app",
"/Applications/Utilities/Migration Assistant.app"
]
s191_apps = ["/Applications/iChat.app",
"/Applications/Facetime.app"
]
s249_apps = ["/Applications/Reflector.app",
"/Applications/Splashtop Streamer.app"
]
s184_apps = ["/Applications/Adobe Bridge CS5.1/Adobe Bridge CS5.1.app",
"/Applications/Adobe Dreamweaver CS5.5/Adobe Dreamweaver CS5.5.app",
"/Applications/Adobe Fireworks CS5.1/Adobe Fireworks CS5.1.app",
"/Applications/Adobe Flash CS5.5/Adobe Flash CS5.5.app",
"/Applications/Adobe Illustrator CS5.1/Adobe Illustrator.app",
"/Applications/Adobe InDesign CS5.5/Adobe InDesign CS5.5.app",
"/Applications/Adobe Photoshop CS5.1/Adobe Photoshop CS5.1.app",
]
#----------FUNCTIONS---------
##########################
def dockutil_remove(user):
call(["/usr/bin/dockutil", "--no-restart", "--remove", "all", user])
#################################
def dockutil_add(app_list, user):
for app in app_list:
print "*ADDING " + app
call(["/usr/bin/dockutil", "--no-restart", "--add", app, user])
###############################
def check_if_plist_exists(user):
dock_plist = user + '/Library/Preferences/com.apple.dock.plist'
if (path.isfile(dock_plist) == False):
username = user.split('/')
print '--------> Creating a .plist for ' + username[2]
copyfile('/System/Library/CoreServices/Dock.app/Contents/Resources/en.lproj/default.plist', dock_plist)
user_gid = getpwnam(username[2])[3]
user_uid = getpwnam(username[2])[2]
chown(dock_plist, user_uid, user_gid)
call(["/usr/bin/defaults", "read", dock_plist, ">/dev/null"])
else:
pass
#############################
def set_dock(app_list, user):
check_if_plist_exists(user)
dockutil_remove(user)
dockutil_add(all_user_apps, user)
dockutil_add(app_list, user)
############################
def add_loc_specific_apps():
print "****" + computer_name[2] + " detected****"
if (computer_name[2] == "S191"):
set_dock(all_user_apps, student_user)
elif (computer_name[2] == "S184"):
set_dock(s184_apps, student_user)
set_dock(s184_apps, testing_user)
elif (computer_name[2] == "S249"):
set_dock(s249_apps, student_user)
else:
set_dock(all_user_apps, student_user)
print "*NO LOCATION-SPECIFIC APPS needed"
#------------------------------
#-------BEGIN SCRIPT-----------
#------------------------------
set_dock(admin_apps, admin_user)
add_loc_specific_apps()
call(["/usr/bin/killall", "Dock"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.