bash 通过 AppleScript 挂载 SMB 驱动器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19727128/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 08:28:23  来源:igfitidea点击:

Mounting an SMB drive via AppleScript

macosbashapplescript

提问by notverypc

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

我编写了运行“mount -t smbfs”命令的 AppleScript 应用程序来安装我们员工使用的 Windows 共享驱动器。

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

的完整输出mountwindowshome是:

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.

任何帮助/指示将不胜感激。

采纳答案by Darrick Herwehe

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:

根据此站点,您必须对特殊字符使用 url 转义。对于@将是 %40的字符,它将把挂载行变成这样:

mount -t smbfs //mystaff:PE91XA!!%[email protected]/Teaching /Users/mystaff/Desktop/DoNotUseTeachingDrive/