Removing default dock items

Jenncat
New Contributor III

I have been able to successfully add dock items but I would like to remove several default items from student users docks.  Do I need to add them to the Dock Items and then delete them?  I don't see any information on how to remove default items like facetime, etc. 

I am new to jamf and have new macs to set up for our classroom labs.  Any help is appreciated.

 

1 ACCEPTED SOLUTION

pete_c
Contributor III

I've been using this for awhile now..

#!/bin/bash

## This allows you to specify lists of items to remove and add in arrays, and then they'll be done in bulk using a for loop
## Items to remove should be the label (usually the name of the application)
## Items to add are the full path to the item to add (usually /Applications/NAMEOFAPP.app)
## A few examples are prepopulated in the arrays, but feel free to tweak as suits the needs of your organization

# original https://raw.githubusercontent.com/aysiu/Mac-Scripts-and-Profiles/master/DockutilAddRemoveArrays.sh
# bash string manipulations here https://www.tldp.org/LDP/LG/issue18/bash.html

# TO-DO: 
# - check for jamf
# - check for dockutil; install from jamf (or download from site)
# - check for AD binding, add Directory Utility if bound
# - check OS version, add System Prefs vs System Settings
# - check OS version, add Safari from proper location

# check for dockutil, call policy if not present

if [[ ! -e "/usr/local/bin/dockutil" ]]; then
   /usr/local/bin/jamf policy -event install-dockutil
fi   

itemsToRemove=(
   "Address Book"
   "App Store"
   "Books"
   "Calendar"
   "Contacts"
   "Dictionary"
   "Downloads"
   "FaceTime"
   "Freehand"
   "iBooks"
   "iPhoto"
   "iTunes"
   "Keynote"
   "Launchpad"
   "Mail"
   "Maps"
   "Messages"
   "Mission Control"
   "Music"
   "News"
   "Notes"
   "Numbers"
   "Pages"
   "Photos"
   "Podcasts"
   "Reminders"
   "Siri"
   "Stocks"
   "TextEdit"
   "TV"
)

itemsToAdd=(
   "/Applications/Google Chrome.app"
   "/Applications/Safari.app"
   "/Applications/Preview.app"
   "/Applications/Utilities/Terminal.app"
   "/Applications/System Preferences.app"
)

for removalItem in "${itemsToRemove[@]}"
   do
      # Check that the item is actually in the Dock
      inDock=$(/usr/local/bin/dockutil --list | /usr/bin/grep "$removalItem")
      if [ -n "$inDock" ]; then
         /usr/local/bin/dockutil --remove "$removalItem" --no-restart
      fi
   done


for additionItem in "${itemsToAdd[@]}"
   do
      # Check that the item actually exists to be added to the Dock and that it isn't already in the Dock
      # Stripping path and extension code based on code from http://stackoverflow.com/a/2664746
      additionItemString=${additionItem##*/}
      additionItemBasename=${additionItemString%.*}
      inDock=$(/usr/local/bin/dockutil --list | /usr/bin/grep "$additionItemBasename")
      if [ -e "$additionItem" ] && [ -z "$inDock" ]; then
            /usr/local/bin/dockutil --add "$additionItem" --no-restart
      fi
   done

sleep 3

/usr/bin/killall Dock

 

View solution in original post

17 REPLIES 17

sdagley
Esteemed Contributor II

@Jenncat Creating Dock Items for the default items you want to remove and then using a Dock Items payload in a Policy to remove them will work. You might want to take a look at dockutil though as that will allow you to script the dock reconfiguration.

I would recommend "dockutil", works like a charm. We use it to create a "standard Dock" during Enrollment Process. Users are able to config it for their use afterwards, in case they like to return to the "standard" or a "clean" Dock, I created two policies in Self Service for this.

pete_c
Contributor III

I've been using this for awhile now..

#!/bin/bash

## This allows you to specify lists of items to remove and add in arrays, and then they'll be done in bulk using a for loop
## Items to remove should be the label (usually the name of the application)
## Items to add are the full path to the item to add (usually /Applications/NAMEOFAPP.app)
## A few examples are prepopulated in the arrays, but feel free to tweak as suits the needs of your organization

# original https://raw.githubusercontent.com/aysiu/Mac-Scripts-and-Profiles/master/DockutilAddRemoveArrays.sh
# bash string manipulations here https://www.tldp.org/LDP/LG/issue18/bash.html

# TO-DO: 
# - check for jamf
# - check for dockutil; install from jamf (or download from site)
# - check for AD binding, add Directory Utility if bound
# - check OS version, add System Prefs vs System Settings
# - check OS version, add Safari from proper location

# check for dockutil, call policy if not present

if [[ ! -e "/usr/local/bin/dockutil" ]]; then
   /usr/local/bin/jamf policy -event install-dockutil
fi   

itemsToRemove=(
   "Address Book"
   "App Store"
   "Books"
   "Calendar"
   "Contacts"
   "Dictionary"
   "Downloads"
   "FaceTime"
   "Freehand"
   "iBooks"
   "iPhoto"
   "iTunes"
   "Keynote"
   "Launchpad"
   "Mail"
   "Maps"
   "Messages"
   "Mission Control"
   "Music"
   "News"
   "Notes"
   "Numbers"
   "Pages"
   "Photos"
   "Podcasts"
   "Reminders"
   "Siri"
   "Stocks"
   "TextEdit"
   "TV"
)

itemsToAdd=(
   "/Applications/Google Chrome.app"
   "/Applications/Safari.app"
   "/Applications/Preview.app"
   "/Applications/Utilities/Terminal.app"
   "/Applications/System Preferences.app"
)

for removalItem in "${itemsToRemove[@]}"
   do
      # Check that the item is actually in the Dock
      inDock=$(/usr/local/bin/dockutil --list | /usr/bin/grep "$removalItem")
      if [ -n "$inDock" ]; then
         /usr/local/bin/dockutil --remove "$removalItem" --no-restart
      fi
   done


for additionItem in "${itemsToAdd[@]}"
   do
      # Check that the item actually exists to be added to the Dock and that it isn't already in the Dock
      # Stripping path and extension code based on code from http://stackoverflow.com/a/2664746
      additionItemString=${additionItem##*/}
      additionItemBasename=${additionItemString%.*}
      inDock=$(/usr/local/bin/dockutil --list | /usr/bin/grep "$additionItemBasename")
      if [ -e "$additionItem" ] && [ -z "$inDock" ]; then
            /usr/local/bin/dockutil --add "$additionItem" --no-restart
      fi
   done

sleep 3

/usr/bin/killall Dock

 

Jenncat
New Contributor III

thank you

Jenncat
New Contributor III

Pete, 

I'm new to jamf and I edited your script for our schools.  The policy is failing.  It looks like a syntax error in line 80/87.  This is the message that I'm getting:

 
 
 
 
 
 
 
Script exit code: 1
Script result: /Library/Application Support/JAMF/tmp/Create Custom Dock Viscom: line 80: unexpected EOF while looking for matching `"'
/Library/Application Support/JAMF/tmp/Create Custom Dock Viscom: line 87: syntax error: unexpected end of file
Error running script: return code was 1.
Could you look at the script and see if anything jumps out to you?

Jenncat
New Contributor III

This is my edited script

#!/bin/bash

## This allows you to specify lists of items to remove and add in arrays, and then they'll be done in bulk using a for loop
## Items to remove should be the label (usually the name of the application)
## Items to add are the full path to the item to add (usually /Applications/NAMEOFAPP.app)
## A few examples are prepopulated in the arrays, but feel free to tweak as suits the needs of your organization

# original https://raw.githubusercontent.com/aysiu/Mac-Scripts-and-Profiles/master/DockutilAddRemoveArrays.sh
# bash string manipulations here https://www.tldp.org/LDP/LG/issue18/bash.html

# TO-DO: 
# - check for jamf
# - check for dockutil; install from jamf (or download from site)
# - check for AD binding, add Directory Utility if bound
# - check OS version, add System Prefs vs System Settings
# - check OS version, add Safari from proper location

# check for dockutil, call policy if not present

if [[ ! -e "/usr/local/bin/dockutil" ]]; then
   /usr/local/bin/jamf policy -event install-dockutil
fi   

itemsToRemove=(
   "Address Book"
   "App Store"
   "Calendar"
   "Contacts"
   "Dictionary"
   "FaceTime"
   "Freehand"
   "iBooks"
   "iPhoto"
   "iTunes"
   "Keynote"
   "Launchpad"
   "Mail"
   "Maps"
   "Messages"
   "Music"
   "News"
   "Notes"
   "Photos"
   "Reminders"
   "TV"
)

itemsToAdd=(
   "/Applications/Google Chrome.app"
   "/Applications/Image Capture.app"
   "/Applications/Self%20Service.app
   "/Applications/Safari.app"
   "/Applications/Adobe Acrobat DC/Adobe Acrobat.app"
   "/Applications/Adobe Illustrator 2023/Adobe Illustrator.app"
   "/Applications/Adobe InDesign 2023/Adobe InDesign 2023.app"
   "/Applications/Adobe Lightroom Classic/Adobe Lightroom Classic.app"
   "/Applications/Adobe Photoshop 2023/Adobe Photoshop 2023.app"
   "/Applications/Final Cut Pro.app"
   "/Applications/System Preferences.app"
)

for removalItem in "${itemsToRemove[@]}"
   do
      # Check that the item is actually in the Dock
      inDock=$(/usr/local/bin/dockutil --list | /usr/bin/grep "$removalItem")
      if [ -n "$inDock" ]; then
         /usr/local/bin/dockutil --remove "$removalItem" --no-restart
      fi
   done


for additionItem in "${itemsToAdd[@]}"
   do
      # Check that the item actually exists to be added to the Dock and that it isn't already in the Dock
      # Stripping path and extension code based on code from http://stackoverflow.com/a/2664746
      additionItemString=${additionItem##*/}
      additionItemBasename=${additionItemString%.*}
      inDock=$(/usr/local/bin/dockutil --list | /usr/bin/grep "$additionItemBasename")
      if [ -e "$additionItem" ] && [ -z "$inDock" ]; then
            /usr/local/bin/dockutil --add "$additionItem" --no-restart
      fi
   done

sleep 3

/usr/bin/killall Dock

 

This script works fine when called upon using sudo jamf policy -id <policy id>

But when run using trigger or from Self Service doesn't work.

I keep it more simple.

This is the script to create our "Standard" Dock during Enrollment Process:

#!/bin/sh

LoggedInUser=$(who | awk '/console/{print $1}')
echo "Logged in User $LoggedInUser"

su $LoggedInUser -c '/usr/local/bin/dockutil --remove all --no-restart'
sleep 2

su $LoggedInUser -c '/usr/local/bin/dockutil --add "/Applications/Safari.app" --position 1 --no-restart'

su $LoggedInUser -c '/usr/local/bin/dockutil --add "/Applications/Firefox.app" --position 2 --no-restart'

su $LoggedInUser -c '/usr/local/bin/dockutil --add "/Applications/Google Chrome.app" --position 3 --no-restart'

su $LoggedInUser -c '/usr/local/bin/dockutil --add "/System//Applications/Reminders.app" --position 4 --no-restart'

su $LoggedInUser -c '/usr/local/bin/dockutil --add "/Applications/Microsoft Teams.app"  --position 5 --no-restart'

su $LoggedInUser -c '/usr/local/bin/dockutil --add "/Applications/Microsoft Outlook.app"  --position 6 --no-restart'

su $LoggedInUser -c '/usr/local/bin/dockutil --add "/Applications/Microsoft Word.app"  --position 7 --no-restart'

su $LoggedInUser -c '/usr/local/bin/dockutil --add "/Applications/Microsoft Excel.app"  --position 8 --no-restart'

su $LoggedInUser -c '/usr/local/bin/dockutil --add "/Applications/Microsoft PowerPoint.app"  --position 9 --no-restart'

su $LoggedInUser -c '/usr/local/bin/dockutil --add "/Applications/Self Service.app" --position 19'
sleep 2

echo "### Script End #####"
sleep 2

 

And this is the one to clean the Dock:

#!/bin/sh

LoggedInUser=$(who | awk '/console/{print $1}')
echo $LoggedInUser

su $LoggedInUser -c '/usr/local/bin/dockutil --remove all --no-restart'
su $LoggedInUser -c '/usr/local/bin/dockutil --add "/Applications/Self Service.app" --position 5'

pkill "Dock"

Jenncat
New Contributor III

I found my error

Mind posting your updated script?

Guys, Can anyone help me out how to install dockutil using the above script? I'm trying to deploy this script in Intune as had an option to remove the icons from the dock not an option to add an icon. Thanks for understanding.

The tool "dockutil" must be distributed via a PKG to the Mac Clients. Check the dockutil documentation for more details:
https://github.com/kcrawford/dockutil#readme

pete_c
Contributor III

All this time and I only now realized that was my ARD version, not my Jamf version (sheepish grin).

This will work from Jamf or from ARD's Send UNIX Command:

#!/bin/bash

## This allows you to specify lists of items to remove and add in arrays, and then they'll be done in bulk using a for loop
## Items to remove should be the label (usually the name of the application)
## Items to add are the full path to the item to add (usually /Applications/NAMEOFAPP.app)
## A few examples are prepopulated in the arrays, but feel free to tweak as suits the needs of your organization

# original https://raw.githubusercontent.com/aysiu/Mac-Scripts-and-Profiles/master/DockutilAddRemoveArrays.sh
# bash string manipulations here https://www.tldp.org/LDP/LG/issue18/bash.html

# TO-DO: 
#  check for jamf
#  check for dockutil; install from jamf (or download from site)
#  check for AD binding, add Directory Utility if bound
#  validate new AD, ARD vs SS checks, & that add to array works as intended
#  check OS version, add System Prefs vs System Settings

# if dockutil is present, bail out
# if dockutil is not present, read jss and try jamf policy first
# if jss is empty OR if jss not empty BUT dockutil still not present, try direct download
# if dockutil still not present, bail out

# variables

currentUser=$(stat -f %Su "/dev/console") # pete
currentHomeFolder=$(dscl . read "/Users/$currentUser" NFSHomeDirectory | awk '{ print $NF }') # /Users/pete
uid=$(id -u "$currentUser") # 501

jss_url=$(defaults read /Library/Preferences/com.jamfsoftware.jamf.plist jss_url)

# run as user since Jamf runs scripts by default, and we're poking userspace

runAsUser() {  
  if [ "$currentUser" != "loginwindow" ]; then
    launchctl asuser "$uid" sudo -u "$currentUser" "$@"
  else
    echo "no user logged in"
    # uncomment the exit command to make the function exit with an error when no user is logged in
    # exit 1
  fi
} 

# get dockutil if not present 

if [[ ! -e "/usr/local/bin/dockutil" ]]; then
        if [[ -z $jss_url ]]; then
	curl --output-dir /private/tmp -O https://github.com/kcrawford/dockutil/releases/download/3.1.3/dockutil-3.1.3.pkg ;
	installer -pkg /private/tmp/dockutil-3.1.3.pkg -target / ;
	sleep 1 ;
fi
   /usr/local/bin/jamf policy -event install-dockutil
fi

itemsToRemove=(
   "Address Book"
   "App Store"
   "Books"
   "Calculator"
   "Calendar"
   "Clock"
   "Contacts"
   "Dictionary"
   "Downloads"
   "FaceTime"
   "Find My"
   "Font Book"
   "Freeform"
   "iBooks"
   "Image Capture"
   "iMovie"
   "iPhoto"
   "iTunes"
   "Keynote"
   "Launchpad"
   "Mail"
   "Maps"
   "Messages"
   "Mission Control"
   "Music"
   "News"
   "Notes"
   "Numbers"
   "Pages"
   "Photos"
   "Podcasts"
   "QuickTime"
   "QuickTime Player"
   "Reminders"
   "Siri"
   "Shortcuts"
   "Stickies"
   "Stocks"
   "TextEdit"
   "Time Machine"
   "TV"
   "Voice Memos"
   "Weather"
)

itemsToAdd=(
   "/Applications/Google Chrome.app"
   "/Applications/Safari.app"
   "/Applications/Preview.app"
   "/Applications/Utilities/Terminal.app"
)

# check for AD binding; this is the modern location (10.15+ iirc)

ADCompName=$(dsconfigad -show | awk -F'= ' '/Computer Account/{print $NF}')

if [[ -n "$ADCompName" ]]; then
    itemsToAdd+=("/System/Library/CoreServices/Applications/Directory Utility.app") # add to itemsToAdd array
fi


# check for ARD, add Screen Sharing otherwise; this is the modern location (10.15+ iirc)

if [[ ! -e "/Applications/Remote Desktop.app" ]]; then
    itemsToAdd+=("/System/Library/CoreServices/Applications/Screen Sharing.app")
else
    itemsToAdd+=("/Applications/Remote Desktop.app")
fi    


# check OS version, add correct System Settings vs Preferences

macOSversionMAJOR=$(/usr/bin/sw_vers -productVersion | /usr/bin/awk -F. '{ print $1}')

if [[ $macOSversionMAJOR == "13" || $macOSversionMAJOR == "14" ]]; then
    itemsToAdd+=("/Applications/System Settings.app")
else
    itemsToAdd+=("/Applications/System Preferences.app")
fi    


for removalItem in "${itemsToRemove[@]}"
   do
      # Check that the item is actually in the Dock
      inDock=$(/usr/local/bin/dockutil --list "${currentHomeFolder}" | /usr/bin/grep "$removalItem")
      if [ -n "$inDock" ]; then
         /usr/local/bin/dockutil --remove "$removalItem" "${currentHomeFolder}" --no-restart
      fi
   done


for additionItem in "${itemsToAdd[@]}"
   do
      # Check that the item actually exists to be added to the Dock and that it isn't already in the Dock
      # Stripping path and extension code based on code from http://stackoverflow.com/a/2664746
      additionItemString=${additionItem##*/}
      additionItemBasename=${additionItemString%.*}
      inDock=$(/usr/local/bin/dockutil --list "${currentHomeFolder}" | /usr/bin/grep "$additionItemBasename")
      if [ -e "$additionItem" ] && [ -z "$inDock" ]; then
            /usr/local/bin/dockutil --add "$additionItem" "${currentHomeFolder}" --no-restart
      fi
   done

sleep 3

/usr/bin/killall Dock

MPHEGGELO
New Contributor

Got lots of "?" using this script

@MPHEGGELO 

The reason for the "?" is probably that the Apps either do not exist on the Mac or the name of the App is not correct written in the script.

I usually drag and drop the App from the Finder window into a open Terminal window to get the exact App Name.

MPHEGGELO
New Contributor

They exist for sure.

 

itemsToAdd=(
"/Applications/Google Chrome.app"
"/Applications/Safari.app"
"/Applications/Microsoft Teams.app"
"/Applications/Microsoft Outlook.app"
"/Applications/Microsoft Word.app"
"/Applications/Microsoft Excel.app"
"/Applications/Microsoft PowerPoint.app"

MPHEGGELO
New Contributor

Run the script on its own:

 

/Users/xxxx/Downloads/DockUtilScript.sh: line 1: #!/bin/bash: No such file or directory

Checking for policies triggered by "install-dockutil" for user "xxx"...

No policies were found for the "install-dockutil" trigger.

/Users/xxxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

/Users/xxxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

/Users/xxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

/Users/xxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

/Users/xxxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

/Users/xxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

/Users/xxxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

/Users/xxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

/Users/xxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

/Users/xxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

/Users/xxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

/Users/xxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

/Users/xxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

/Users/xxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

/Users/xxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

/Users/xxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

/Users/xxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

/Users/xxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

/Users/xxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

/Users/xxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

/Users/xxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

/Users/xxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

/Users/xxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

/Users/xxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

/Users/xxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

/Users/xxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

/Users/xxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

/Users/xxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

/Users/xxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

/Users/xxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

/Users/xxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

/Users/xxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

/Users/xxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

/Users/xxx/Downloads/DockUtilScript.sh: line 125: /usr/local/bin/dockutil: No such file or directory

 

 

...you get the picture