Posted on 01-05-2023 07:12 AM
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
Solved! Go to Solution.
Posted on 01-05-2023 08:43 AM
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
Posted on 01-05-2023 08:13 AM
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.
Posted on 01-05-2023 08:24 AM
Thanks for the suggestion but I'm not concerned with the Dock, only Finder Desktop icons.
Posted on 01-05-2023 08:44 AM
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!
Posted on 01-05-2023 08:43 AM
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
Posted on 01-06-2023 04:29 AM
Could also do a Configuration Profile. This way, users can't uncheck the 4 boxes.
Posted on 01-10-2023 05:06 AM
@obi-k i was going to suggest this nice one 😁