I am aware of dockutil in homebrew but, I am trying to run a bash script that automatically adds dock icons to the dock on a fresh user account. dockutil has been uncooperative on fresh out of the box installs:

#add items to dock
x="defaults write com.apple.dock persistent-apps -array-add "
eval $f\Google Chrome.app$z;
eval $f\Safari.app$z;
eval $f\Firefox.app$z;
eval $f\Messages.app$z;
eval $f\Slack.app$z;
eval $f\Microsoft Outlook.app$z;
eval $f\Microsoft Word.app$z;
eval $f\Microsoft Excel.app$z;
eval $f\App Store.app$z;
eval $f\System Preferences.app$z;
eval $f\zoom.us.app$z;
killall Dock; sleep 1;
eval clear;
exit 0

The script is fine, but I am wondering if there is a more elegant solution to concatenating the x and y variables together into 'f', or if there is a way to combine all three, x,y, and z, into one variable that will allow me to input 'AnyApp.app' in the middle. Input appreciated, thanks!

1 Answer 1


Storing parts of commands in variables and/or using eval is a good way to get weird parsing problems. I'd use a shell function instead:

addDockApp() {
    defaults write com.apple.dock persistent-apps -array-add \

addDockApp "Google Chrome.app"
addDockApp "Safari.app"

Alternately, you could write it as a loop, and iterate over the list of apps to add:

for app in "Google Chrome.app" "Safari.app" "Firefox.app" "Messages.app" \
    "Slack.app" "Microsoft Outlook.app" "Microsoft Word.app" "Microsoft Excel.app" \
    "App Store.app" "System Preferences.app" "zoom.us.app"
    defaults write com.apple.dock persistent-apps -array-add \
  • Thank you! I think I will make an array and then parse them into the loop so that I can have a nice vertical list of the .apps. I will also practice making functions where applicable...appreciate the insight! Cheers! Sep 16, 2019 at 22:21
  • @input_error An array's a good way to manage the app list, just be sure to use double-quotes and [@] when you expand it (e.g. for app in "${app_list[@]}"; do). Sep 16, 2019 at 22:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .