Reputation: 121
I am currently working on a shell script for a small business Mac environment. The intention of the script is to add a few applications to the dock.
I can run the commands via terminal individually, but I am unable to run them in a shell script. The script only completes the "killall Dock" command, no errors or warnings.
This is the code I attempted:
#!/bin/sh
defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>/Applications/Firefox.app</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'
defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>/Applications/Calculator.app</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'
defaults write com.apple.dock persistent-others -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>/Users/Shared/RMS.fmp12</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'
killall Dock
exit 0
Update:
I attempted to execute the 'defaults' command while in bash (i.e 'sudo bash') and it does not appear to have any effect.
When I run the exact same command in a normal terminal it works.
defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>/Applications/Firefox.app</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'
Upvotes: 2
Views: 1286
Reputation: 670
The defaults command changes settings for a particular user. When you use sudo you run the defaults command, not as the current user, but as a different user (i.e. root).
From your description it sounds like defaults is changing the settings for the root user (because that is who sudo makes it run as) so when Dock is restarted (and run as the current user) it doesn't see any settings changes.
There should be no reason to use sudo in your particular case. A user can change their own settings with no special permissions and Dock is also run as the current user and so can be killed. Therefore just run the script (e.g. sh script.sh
) and it should work.
Should you still have problems then I would come back with exactly what you are typing and the output of defaults read ...
after running.
Upvotes: 1