Skip to main content
Solved

Help with AppleScript mounting home directory share drive

  • April 8, 2022
  • 4 replies
  • 42 views

mvu
Forum|alt.badge.img+20
  • Jamf Heroes
  • 963 replies

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

 

Best answer by YanW

#!/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

4 replies

YanW
Forum|alt.badge.img+11
  • Contributor
  • 180 replies
  • Answer
  • April 8, 2022
#!/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

mvu
Forum|alt.badge.img+20
  • Author
  • Jamf Heroes
  • 963 replies
  • April 8, 2022
#!/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

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.

 


YanW
Forum|alt.badge.img+11
  • Contributor
  • 180 replies
  • April 8, 2022

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.

 


This is the basic idea

set userName to do shell script "whoami" mount volume "smb://example.com/networkshares/Home%20Directories/" & userName

 


mvu
Forum|alt.badge.img+20
  • Author
  • Jamf Heroes
  • 963 replies
  • April 8, 2022

This is the basic idea

set userName to do shell script "whoami" mount volume "smb://example.com/networkshares/Home%20Directories/" & userName

 


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.