Posted on 10-29-2023 06:32 PM
I'm trying to run a VERY simple script that mounts a folder based on user login -
open "smb://server/staffhome$/$(whoami)"
This works perfectly in terminal but when putting it as a process to execute on login it keeps on being unable to find the location?
Posted on 10-29-2023 08:06 PM
@JAMFNoob That command relies on being run as the logged in suer, and if you're running it via a script or a files & process command in a Jamf Pro policy that doesn't run as the logged in user. To see how to run a command as the logged in user take a look at the following blog post: https://scriptingosx.com/2020/08/running-a-command-as-another-user/
Posted on 10-30-2023 07:32 AM
In this particular case you may be better creating a LaunchAgent on the local Mac. LaunchAgents run in the user context.
Posted on 10-30-2023 07:42 AM
Could you try this?
#!/bin/bash
currentuser=$(/usr/bin/who | awk '/console/{ print $1 }')
/usr/bin/osascript > /dev/null << EOT
tell application "Finder"
activate
mount volume "smb://server/staffhome$/${currentuser}/"
end tell
EOT
Posted on 10-30-2023 02:53 PM
This didn't work for me - although I did try the below but still failing to get to the user's folder, just takes me to the staff directory above it
currentUser=$( echo "show State:/ Users/ConsoleUser" | scutil | awk '/ Name :/ { print $3 }' )
open "smb://server/staffhome$/$currentUser"
Posted on 10-31-2023 02:50 AM
Your script isn't running in the user context, when jamf executes it, it's run as root.
sudo -u $currentUser open "smb://server/staffhome$/$currentUser"
Might work...