Command to set Desktop icons

Veronica_G
New Contributor

Hello, I am trying to set desktop icons as visible with a script. I assume I can do a "defaults write ..." to some plist file to set these options, but after setting them myself while running Composer to try to see which file was edited, I was lost in plist confusion.

To be clear, the settings are shown in the GUI under Finder settings (In Finder, type command comma and click the General tab) as:

Hard Disks
External Disks
CDs, DVDs, and iPods
Connected Servers

 

I would like to set those four as visible (checked) via command.

 

Thanks for any help anyone can provide

1 ACCEPTED SOLUTION

YanW
Contributor III

Maybe give this a try

#!/bin/bash

currentuser=`stat -f "%Su" /dev/console`

su "$currentuser" -c "defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool true;"
su "$currentuser" -c "defaults write com.apple.finder ShowHardDrivesOnDesktop -bool true;"
su "$currentuser" -c "defaults write com.apple.finder ShowMountedServersOnDesktop -bool true;"
su "$currentuser" -c "defaults write com.apple.finder ShowRemovableMediaOnDesktop -bool true;"

#Restarts cfprefsd and Finder
killAll cfprefsd
killAll Finder

exit

View solution in original post

6 REPLIES 6

macinblack
New Contributor III

Allow me to make a recommendation. The native tools that macOS and Jamf have for dock management are clunky and frustrating to use. The dockutil project simplifies things: https://github.com/kcrawford/dockutil.

Thanks for the suggestion but I'm not concerned with the Dock, only Finder Desktop icons.

So sorry. I have no idea how I misread this so badly. Anyhow, for your issue, I think what you're looking for is:

Off
defaults write com.apple.finder CreateDesktop false; killall Finder

On
defaults write com.apple.finder CreateDesktop true; killall Finder

Use this to see all attributes:

defaults read com.apple.finder

And this to see the current CreateDesktop setting:

defaults read com.apple.finder CreateDesktop

I hope this is more helpful!

YanW
Contributor III

Maybe give this a try

#!/bin/bash

currentuser=`stat -f "%Su" /dev/console`

su "$currentuser" -c "defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool true;"
su "$currentuser" -c "defaults write com.apple.finder ShowHardDrivesOnDesktop -bool true;"
su "$currentuser" -c "defaults write com.apple.finder ShowMountedServersOnDesktop -bool true;"
su "$currentuser" -c "defaults write com.apple.finder ShowRemovableMediaOnDesktop -bool true;"

#Restarts cfprefsd and Finder
killAll cfprefsd
killAll Finder

exit

obi-k
Valued Contributor II

Could also do a Configuration Profile. This way, users can't uncheck the 4 boxes.

Screenshot_2023-01-06_at_7_25_34_AM.png

ScottMcGorie
New Contributor

@obi-k i was going to suggest this nice one 😁