diff --git a/System Configs/create_Shortcut.sh b/System Configs/create_Shortcut.sh index 00e89d5..847f07e 100644 --- a/System Configs/create_Shortcut.sh +++ b/System Configs/create_Shortcut.sh @@ -3,7 +3,7 @@ ################################################################################################### # Script Name: create_Shortcut.sh # By: Zack Thompson / Created: 3/26/2018 -# Version: 0.2 / Updated: 3/27/2018 / By: ZT +# Version: 0.3 / Updated: 4/5/2018 / By: ZT # # Description: This script will create a website shortcut in a specified location with a specified icon. # @@ -28,7 +28,7 @@ echo "***** Create Shortcut process: START *****" getHelp() { echo " -usage: jamf_CreateShortcut.sh +usage: jamf_CreateShortcut.sh [ Dock | Desktop] Info: This script will create a website shortcut in a specified location with a specified icon. @@ -83,40 +83,47 @@ echo "Adding the requested icon..." /usr/bin/python -c "import Cocoa; import sys; Cocoa.NSWorkspace.sharedWorkspace().setIcon_forFile_options_(Cocoa.NSImage.alloc().initWithContentsOfFile_(sys.argv[1].decode('utf-8')), sys.argv[2].decode('utf-8'), 0) or sys.exit(\"Unable to set file icon\")" "${icon}" "${defaultLocation}/${fileName}.url" # Check where to place the file. -if [[ "${location}" == "Dock" ]]; then +case "${location}" in + Dock ) + # Setting a variable that holds whether the Dock item already exists or not (if it does, we don't want to unnecessarily edit and kill the Dock). + alreadyExists=0 - # Setting a variable that holds whether the Dock item already exists or not (if it does, we don't want to unnecessarily edit and kill the Dock). - alreadyExists=0 + # Get the number of items in the persistent-others node; then subtract one for Array value notation. + indexItem=$(/usr/libexec/PlistBuddy -x -c "Print :persistent-others" "/Users/${currentUser}/Library/Preferences/com.apple.dock.plist" | /usr/bin/xmllint --format - | /usr/bin/xpath 'count(//plist/array/dict)' 2>/dev/null) + indexItem=$((indexItem-1)) - # Get the number of items in the persistent-others node; then subtract one for Array value notation. - indexItem=$(/usr/libexec/PlistBuddy -x -c "Print :persistent-others" "/Users/${currentUser}/Library/Preferences/com.apple.dock.plist" | /usr/bin/xmllint --format - | /usr/bin/xpath 'count(//plist/array/dict)' 2>/dev/null) - indexItem=$((indexItem-1)) + # Loop through all the items in the persistent-others node and compare to the new item being added. + for ((i=1; i<=$indexItem; ++i)); do + indexLabel=$(/usr/libexec/PlistBuddy -c "Print :persistent-others:${i}:tile-data:file-label" "/Users/${currentUser}/Library/Preferences/com.apple.dock.plist") + indexData=$(/usr/libexec/PlistBuddy -c "Print :persistent-others:${i}:tile-data:file-data:_CFURLString" "/Users/${currentUser}/Library/Preferences/com.apple.dock.plist") - # Loop through all the items in the persistent-others node and compare to the new item being added. - for ((i=1; i<=$indexItem; ++i)); do - indexLabel=$(/usr/libexec/PlistBuddy -c "Print :persistent-others:${i}:tile-data:file-label" "/Users/${currentUser}/Library/Preferences/com.apple.dock.plist") - indexData=$(/usr/libexec/PlistBuddy -c "Print :persistent-others:${i}:tile-data:file-data:_CFURLString" "/Users/${currentUser}/Library/Preferences/com.apple.dock.plist") + # Check if the current indexItem values equal the new items' values. + if [[ "${indexLabel}" == "${fileName}" && "${indexData}" == "file://${defaultLocation}/${fileName}.url" ]]; then + alreadyExists=1 + echo "Already exists!" + fi + done - # Check if the current indexItem values equal the new items' values. - if [[ "${indexLabel}" == "${fileName}" && "${indexData}" == "file://${defaultLocation}/${fileName}.url" ]]; then - alreadyExists=1 - echo "Already exists!" + # If the new item does not already exist, add it to the Dock. + if [[ $alreadyExists == 0 ]]; then + echo "Adding to the dock..." + fileNameLocation=$(echo "${fileName}" | /usr/bin/sed 's/ /%20/g') + /usr/bin/sudo -s -u "${currentUser}" /usr/bin/defaults write "/Users/${currentUser}/Library/Preferences/com.apple.dock" persistent-others -array-add "tile-datafile-data_CFURLStringfile://${defaultLocation}/${fileNameLocation}.url_CFURLStringType15file-label${fileName}file-type32tile-typefile-tile" + /usr/bin/killall Dock fi - done - - # If the new item does not already exist, add it to the Dock. - if [[ $alreadyExists == 0 ]]; then - echo "Adding to the dock..." - fileNameLocation=$(echo "${fileName}" | /usr/bin/sed 's/ /%20/g') - /usr/bin/sudo -s -u "${currentUser}" /usr/bin/defaults write "/Users/${currentUser}/Library/Preferences/com.apple.dock" persistent-others -array-add "tile-datafile-data_CFURLStringfile://${defaultLocation}/${fileNameLocation}.url_CFURLStringType15file-label${fileName}file-type32tile-typefile-tile" - /usr/bin/killall Dock - fi - -else - # Move file to the specified location if not adding to the Dock. - echo "Moving file in place..." - /bin/mv "${defaultLocation}/${fileName}.url" "${location}" -fi + ;; + Desktop ) + # Move file to the specified location if not adding to the Dock. + echo "Moving file in place..." + /bin/mv "${defaultLocation}/${fileName}.url" "/Users/${currentUser}/Desktop" + ;; + * ) + echo "ERROR: The specified location is not configurable at this time." + # Function getHelp + getHelp + echo "***** Create Shortcut process: FAILED *****" + ;; +esac echo "***** Create Shortcut process: COMPLETE *****" exit 0 \ No newline at end of file