Mount Network Share to Desktop

jared_f
Valued Contributor

Hi,

I wrote this simple script to mount out network drives. I got it to allow the user to mount to the finder but, then they have to drag their folder over to the desktop. Is there any way I can have the script check who is logged in and then mount their folder to their desktop?

Thanks, Jarede84581351d264055976b5ad1172730b6

1 ACCEPTED SOLUTION

BOBW
Contributor II

check out :

https://jamfnation.jamfsoftware.com/discussion.html?id=14262#responseChild86562

@davidacland script is what I use and it works fine

I do add a few lines though to grab current logged in user and make sure drive is mounted on desktop

#!/bin/bash

theuser=$(/usr/bin/who | awk '/console/{ print $1 }')
/usr/bin/osascript > /dev/null << EOT

        tell application "Finder" 
        activate
        mount volume "smb://zfssa1/home_staff/${theuser}/"
        end tell


EOT

echo $theuser
killall cfprefsd
defaults write com.apple.finder ShowMountedServersOnDesktop true
killall -HUP Finder

View solution in original post

8 REPLIES 8

BOBW
Contributor II

check out :

https://jamfnation.jamfsoftware.com/discussion.html?id=14262#responseChild86562

@davidacland script is what I use and it works fine

I do add a few lines though to grab current logged in user and make sure drive is mounted on desktop

#!/bin/bash

theuser=$(/usr/bin/who | awk '/console/{ print $1 }')
/usr/bin/osascript > /dev/null << EOT

        tell application "Finder" 
        activate
        mount volume "smb://zfssa1/home_staff/${theuser}/"
        end tell


EOT

echo $theuser
killall cfprefsd
defaults write com.apple.finder ShowMountedServersOnDesktop true
killall -HUP Finder

jared_f
Valued Contributor

@BOBW Thank you very much. It worked perfectly.

McKinnonTech
New Contributor III

@BOBW that works, but it asked for a password and pre-fills the users "name" not their AD username.

Is there any way for the script to authenticate based on who's logged in?

BOBW
Contributor II

@McKinnonTech yeah, im not 100% sure how to get the current AD user account, we work with local accounts therefore getting the use with above method works fine, maybe using dscl could get it for you.
There is also a script somewhere in JAMF Nation to use kerberos as authentication.

I will try to find them and let you know

Rocky
New Contributor III

You can use this command to mount the user's network drive:

sudo -u $3 /usr/local/jamf/bin/jamf mount -server SERVER.COMPANY.DOMAIN -share "SHARENAME" -type smb -visible

$3 is the variable user is stored in at login

if you're mounting an afp the type would be afp rather than smb.

jared_f
Valued Contributor

@McKinnonTech That is the same issue we are running into. We have out server set to scope a folder for each person who logins with their credentials. The issue. . . terminal opens and I added a command to close it but, it won't work because it attempts to close before the script was ran. I wish it could pull the users login credentials and auto mount.

McKinnonTech
New Contributor III

@jared_f I ended up using a script written by @Look over here (the second most recent on in the post):
https://jamfnation.jamfsoftware.com/discussion.html?id=15108

I'm running 10.11.16 and mounting a Synology SMB share, which creates/maps users home drives for you.

Maybe give that script in the post above a go with your set up.

jared_f
Valued Contributor

@McKinnonTech I will take a look. Thanks!