Skip to main content
Question

Script works locally but not via Policy


Forum|alt.badge.img+3

A very simple script to add the Movies folder to the sidebar upon login does not work even though the policy logs return a completed status.

#!/bin/zsh
#
# Add the logged in user's "Movies" folder to the Finder Sidebar

# Get the HOME value for the user that's logging in;
# The username is passed as script argument 3
HOMEDIR=$(sudo -u $3 echo $HOME)

# Use the `mysides` command to add the alias/shortcut
/usr/local/bin/mysides add Movies file:///$HOMEDIR/Movies

Mysides is installed on the client via Policy and various iterations of the script "work" according to the logs but the folder does not actually append to the sidebar unless it is executed locally. Very curious where the hangup may be in Jamf...

5 replies

PaulHazelden
Forum|alt.badge.img+12

When you say locally, do you mean the current logged in user runs the commands?

If it is, then the policy is running the command as root, and the locally is running the command as the current user. Try setting the last line to sudo $3 in the front of it, to run the line as the logged in user...

sudo -u $3 /usr/local/bin/mysides add Movies file:///$HOMEDIR/Movies

Forum|alt.badge.img+18
  • Contributor
  • 475 replies
  • May 19, 2021

Although mysides is not guaranteed to work any longer you should try to use this:

#!/bin/zsh

loggedInUser=$( echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/ && ! /loginwindow/ { print $3 }' )
loggedInUserHome=$(/usr/bin/dscl . -read "/users/$loggedInUser" NFSHomeDirectory | cut -d " " -f 2)

if [[ -n "$loggedInUser" ]]; then
    if [[ -n "$loggedInUserHome" ]]; then
        echo "Adding Movies to $loggedInUser's Finder Sidebar..."
        /usr/local/bin/mysides add Movies "file:///$loggedInUserHome/Movies"
    else
        echo "Error: Could not determine $loggedInUser's home folder."
        exit 1
    fi
else
    echo "Nobody is logged in; skipping."
fi

exit 0

Forum|alt.badge.img+3
  • Author
  • New Contributor
  • 2 replies
  • May 20, 2021

@PaulHazelden sorry I forgot to mention that I've tried that iteration already to no avail.

@ryan.ball no luck with that script.


Forum|alt.badge.img+18
  • Contributor
  • 475 replies
  • May 21, 2021

@user-VrNMiDTLrF I don't think it is the script syntax is causing you the issue. I think that mysides is not supported with later macOS versions like I mentioned initially. Check out the issues created on the mysides github.


Forum|alt.badge.img+3
  • Author
  • New Contributor
  • 2 replies
  • May 21, 2021

@ryan.ball Yeah, with that in mind I'm going to try deploying a LaunchAgent instead. Thanks for your help.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings