Help with AppleScript mounting home directory share drive

obi-k
Valued Contributor III

Hi there,

I'm trying to create an AppleScript to mount a network home drive for logged in users. Our current Python Script is dead with 12.3.

I'd like to map the drive for the current user in the script below. Instead of jane.doe, I tried using $3, $User, ~ and a bunch of brackets. How can I replace jane.doe with the current signed in user?

 

tell application "Finder"

open location "smb://example.com/networkshares/Home%20Directories/jane.doe"

end tell

 

2 ACCEPTED SOLUTIONS

YanW
Contributor III
#!/bin/bash

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

        tell application "Finder" 
        activate
        mount volume "smb://example.com/networkshares/Home%20Directories/${currentuser}/"
        end tell

EOT

View solution in original post

YanW
Contributor III

This is the basic idea

set userName to do shell script "whoami"

mount volume "smb://example.com/networkshares/Home%20Directories/" & userName

 

View solution in original post

4 REPLIES 4

YanW
Contributor III
#!/bin/bash

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

        tell application "Finder" 
        activate
        mount volume "smb://example.com/networkshares/Home%20Directories/${currentuser}/"
        end tell

EOT

obi-k
Valued Contributor III

Yeah, that worked. I'm trying to embed this in an AppleScript so I can push it out as an App. Do you know how to embed this bash script into AppleScript?

I'm trying the "do shell script" command.

Screen Shot 2022-04-08 at 1.47.54 PM.png

 

YanW
Contributor III

This is the basic idea

set userName to do shell script "whoami"

mount volume "smb://example.com/networkshares/Home%20Directories/" & userName

 

obi-k
Valued Contributor III

Woah, that worked! Thanks a lot @YanW!

This will give me 2 options to let users open this in Self Service and download the AppleScript Apps to their Dock and open. Very cool.