Mounting an SMB drive via AppleScript

2020-07-27 02:05发布

问题:

I've written and AppleScript App that runs a "mount -t smbfs " command to mount a Windows Shared drive that our Staff use.

The App has been used successfully for a number of months until today. If a user has an @ symbol in their password the application fails. The path is rejected.

Here's the script:

-- Teaching Drive Access

--Get The Shortname and PC Password of current user 
--set PCusername to (short user name of (system info))
set PCusername to "benstaff"
--set PCPassword to text returned of (display dialog "What's your PC Password?" default answer "" with title "T Drive" with icon stop with hidden answer)

--Create Sharepoint on Desktop
set FolderTarget to (path to desktop folder as text) & "DoNotUseTeachingDrive"

try
    FolderTarget as alias
on error
    do shell script "mkdir /Users/" & PCusername & "/Desktop/DoNotUseTeachingDrive/"
end try

set mountcommand to "mount -t smbfs "
set mountuser to "//" & PCusername & ":" & PCPassword
set mountuser to "//" & PCusername & ":" & PCPassword
set mountvolume to "@ncs-srv-fs3.ncs.local/Teaching"
set machomepath to "/Users/" & PCusername & "/Desktop/DoNotUseTeachingDrive/"

set mountwindowshome to mountcommand & mountuser & mountvolume & " " & machomepath as string
do shell script mountwindowshome

The full output of the mountwindowshome is:

mount -t smbfs //mystaff:PE91XA!!@@ncs-srv-fs3.ncs.local/Teaching /Users/mystaff/Desktop/DoNotUseTeachingDrive/

If I run the command in the Terminal without the password I am asked for a password and the share is mounted correctly.

Any help/pointers would be gratefully received.

回答1:

According to this site, you have to use url escaping on special characters. For the @ character that would be %40, which would turn the mount line into this:

mount -t smbfs //mystaff:PE91XA!!%40@ncs-srv-fs3.ncs.local/Teaching /Users/mystaff/Desktop/DoNotUseTeachingDrive/