Why does this not work?

JAMFNoob
New Contributor III

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?

5 REPLIES 5

sdagley
Esteemed Contributor II

@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/

dsavageED
Contributor III

In this particular case you may be better creating a LaunchAgent on the local Mac. LaunchAgents run in the user context.

https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters...

 

obi-k
Valued Contributor III

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

JAMFNoob
New Contributor III

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"

dsavageED
Contributor III

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...