From 9ed06b876e244b1c00524a990e3485719bd2ce0a Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Thu, 15 Jan 2015 20:24:54 -0500 Subject: [PATCH] Reset and save are done, fighting with the load Still trying to figure out how to get the JSON to load properly. Wanted to stash the changes thus far before I fucked anything up really bad. --- dockprof | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 dockprof diff --git a/dockprof b/dockprof new file mode 100755 index 0000000..42ca443 --- /dev/null +++ b/dockprof @@ -0,0 +1,60 @@ +#!/usr/bin/env bash + +case $# in + 1|2) + if [ $1 == reset ]; then + read -p 'Are you sure you want to reset your dock to the factory defaults (y/n)? ' -n 1 -r + + if [[ $REPLY =~ ^[Yy]$ ]] + then + defaults delete com.apple.dock + killall Dock + fi + else + # Checks that a profile name was specified + case $1 in + save|load) + if [ -z $2 ]; then + echo 'Error: You must specify a profile name' + exit 1 + else + PROFILE=~/Library/Preferences/$2.com.apple.dock.json + + if [ $1 == save ]; then + # Checks if profile exists, if so, prompt to overwrite + + if [ -e $PROFILE ]; then + read -p "Would you like to overwrite the profile '$2' (y/n)? " -n 1 -r + + if [[ ! $REPLY =~ ^[Yy]$ ]] + then + echo 'Save aborted' + exit + fi + fi + + defaults read com.apple.dock > $PROFILE + else + # Checks if profile exists, if not, error + + defaults delete com.apple.dock + defaults write com.apple.dock '`cat $PROFILE`' + echo "defaults write com.apple.dock '`cat $PROFILE`'" + + killall Dock + fi + fi + ;; + *) + echo 'Error: Invalid command, expecting reset, save or load' + exit 1 + ;; + esac + fi + ;; + *) + echo 'Usage: dockprof [reset|save|load] [profile]' + exit 1 + ;; +esac +