AppleScript to map server drive

Hi,
So my company runs everything windows but we have 3 Macs in total. We recently added them to our domain but have a problem whenever someone logs in it says they don’t have permissions to view the shared drive. It’s not the case its just that each user has specific access based on their position. So what I’ve done is write an Automator Application that runs a Get Specified Servers and then Connect to Servers. This works for all but one, the users specific drive. Right now its located at smb://“companyname”-fs1/users/“usersname”/. So when I login my username would be different than someone elses so the applescript I have that runs like:

on run {input,parameters}
tell application “Finder”
try
mount volume "smb://“companyname”-fs1/users/“username”/
end try
end tell
return input
end run

What I need is a command that will get the name of whoever is logged in and retrieve their specific drive. I read that $USER is the equivalent of %USERNAME% but when I try that it doesn’t work. I’m a novice at Macs in general but I’m trying to create something that we can give to anyone who uses Mac so that they don’t have to click anything each time they login. I guess I could just manually write their name into the command for everyone who logs in but I would prefer it to just work without that. I’ve visited a dozen different forums and guides but nothing I’ve tried from them work. Help please?

tell application "System Events" to set userName to full name of current user

or

tell application "System Events" to set userName to name of current user

Depending on which you want.

First of all mount volume is part of Standard Additions. It’s not related to the Finder.

Alternatively get the user name from system info

on run {input, parameters}
	set username to short user name of (system info)
	try
		mount volume "smb://companyname-fs1/users/" & username & "/"
	end try
	return input
end run

I think that connecting to SMB volume sometimes requires volume name + user name: so username would read like Volume/Username instead of just Username.
Can you give it a try?

Ah I basically just copied something from another forum to create that. Again, I have no idea what I’m doing on Mac. Thanks for the input. I will try this and let you know if it works.

Ok thank you so much! It works! The only thing I’m looking for a solution now is how to not have it open multiple finder windows for each drive it mounts.I would like for it to run quietly in the background on login.

You can mount volumes without them opening in the Finder when they mount using command line, as shown in this very old thread here:

https://discussions.apple.com/thread/2220889