通过AppleScript安装SMB驱动器

时间:2013-11-01 12:52:04

标签: macos bash applescript

我写过并运行“mount -t smbfs”命令的AppleScript App来安装我们员工使用的Windows共享驱动器。

该应用程序已成功使用了几个月,直到今天。如果用户的密码中包含@符号,则应用程序将失败。路径被拒绝了。

这是脚本:

-- 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

mountwindowshome的完整输出是:

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

如果我在没有密码的终端中运行命令,我会被要求输入密码并正确安装共享。

感谢任何帮助/指示。

1 个答案:

答案 0 :(得分:2)

根据this site,你必须在特殊字符上使用url转义。对于将为%40的@字符,这会将挂载行转换为:

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