Posted on 03-23-2017 12:17 PM
Trying to get my HD and connected servers to be on the desktop by default. I have a script that, when ran on my main computer, works great..... When I try to use the trigger on the test machine it doesnt seem to want to relaunch the finder even though I have the killall Finder command in the script.....
defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool true
defaults write com.apple.finder ShowHardDrivesOnDesktop -bool true
defaults write com.apple.finder ShowRemovableMediaOnDesktop -bool true
defaults write com.apple.finder ShowMountedServersOnDesktop -bool true
killall Finder
I have that set in as a Policy in JSS. When I run the custom trigger, it doesn't fully relaunch the Finder as it does on my main machine.
Solved! Go to Solution.
Posted on 03-23-2017 02:26 PM
Oh! I didn't even really look closely at your script. The problem is you're trying to run the command against the preferences for the account running the script. which is likely going to be either your management account, or root.
In short, whenever you use syntax with defaults like defaults write com.company.domain
without referencing the full path to the plist, defaults uses the path of the account running the script to locate the plist. In this case, you want it to affect the logged in user, not root or your Jamf management account. So in essence, it IS working, just not on the logged in account, which is why it doesn't appear to be working.
There are several ways to fix this.
sudo -u $user <commands>
Personally I have mixed results with option 2, and much better results with option 1. However, there is another way to do option 2 that is more reliable, using the launchctl asuser
method. See this post for an example of how it works.
Lastly, have you considered using a Config Profile for this instead of trying to script it? Is it something you want to enforce, or just set once? A Configuration Profile can let you set and enforce the setting I believe.
Posted on 03-23-2017 02:33 PM
Why not use a profile for this?
Posted on 03-23-2017 12:34 PM
You can try adding an open command after the killall. Either of the examples below should work.
open /System/Library/CoreServices/Finder.app
open -a Finder
Posted on 03-23-2017 01:40 PM
LSOpenURLsWithRole() failed with error -600 for the file /System/Library/CoreServices/Finder.app.
Received the following error using either "open" command.
Posted on 03-23-2017 01:49 PM
Is the issue you're running into that the Finder won't restart at all, or is it restarting and failing to come back up fully?
Posted on 03-23-2017 02:01 PM
It looks like the finder is restarting but the commands other than the killall Finder are not working.
When I run the custom trigger, the icons on the desktop disappear and come back but no HD or connected servers show up and the preferences remain unchecked.
I created the script in TrextWrangler and ran it on the machine it was created on and it worked just as it should.
Posted on 03-23-2017 02:26 PM
Oh! I didn't even really look closely at your script. The problem is you're trying to run the command against the preferences for the account running the script. which is likely going to be either your management account, or root.
In short, whenever you use syntax with defaults like defaults write com.company.domain
without referencing the full path to the plist, defaults uses the path of the account running the script to locate the plist. In this case, you want it to affect the logged in user, not root or your Jamf management account. So in essence, it IS working, just not on the logged in account, which is why it doesn't appear to be working.
There are several ways to fix this.
sudo -u $user <commands>
Personally I have mixed results with option 2, and much better results with option 1. However, there is another way to do option 2 that is more reliable, using the launchctl asuser
method. See this post for an example of how it works.
Lastly, have you considered using a Config Profile for this instead of trying to script it? Is it something you want to enforce, or just set once? A Configuration Profile can let you set and enforce the setting I believe.
Posted on 03-23-2017 02:31 PM
The finder preferences are user specific, so the defaults write command has to be run as the logged in user to affect that user's settings. Luckily, since the script is being run as root, you can use su -l to run the command as the current user without a password prompt, though you will still need to target the plist directly.
#!/bin/bash
currentuser=$(/bin/ls -la /dev/console | /usr/bin/cut -d ' ' -f 4)
su -l $currentuser -c "defaults write /Users/$currentuser/Library/Preferences/com.apple.finder ShowExternalHardDrivesOnDesktop -bool true"
su -l $currentuser -c "defaults write /Users/$currentuser/Library/Preferences/com.apple.finder ShowHardDrivesOnDesktop -bool true"
su -l $currentuser -c "defaults write /Users/$currentuser/Library/Preferences/com.apple.finder ShowRemovableMediaOnDesktop -bool true"
su -l $currentuser -c "defaults write /Users/$currentuser/Library/Preferences/com.apple.finder ShowMountedServersOnDesktop -bool true"
killall Finder
I don't remember if this method does anything funny with the permissions on the plist, so you may need to throw a chown/chmod at the end.
Posted on 03-23-2017 02:33 PM
Why not use a profile for this?
Posted on 03-23-2017 02:44 PM
Thank for all the info. I will try messing around with some of this tomorrow.
I am relatively new to this but picking things up pretty quick.
How am i able to do this with a profile, bentoms? It looks like you tried to attach a pic but its not showing.
Posted on 03-23-2017 03:00 PM
I'll do some research on the Config Profile and see if I can use that.
Thanks.
Posted on 03-24-2017 08:22 AM
I actually am doing that now with a profile ...back in the day I converted my old MCX to a profile with mcxtoprofile. I don't have a choice ... some of my old Mac OS 9 users expect to see those there were they were a file I work ticke expect to see those there were they or they will file a ticket... I will gladly share my profile once I get back to the office .
Posted on 03-24-2017 10:40 AM
I figured it out. Looks like there is a lot of power in Config Profiles and very easy to setup and scope out.
Thanks everyone.