macos - 通过 AppleScript 安装 SMB 驱动器

标签 macos bash applescript

我编写了一个 AppleScript 应用程序,它运行“mount -t smbfs”命令来安装我们员工使用的 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/

如果我在没有密码的情况下在终端中运行命令,系统会要求我输入密码,并且共享已正确安装。

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

最佳答案

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

mount -t smbfs //mystaff:PE91XA!!%<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="487c7808262b3b653b3a3e652e3b7b66262b3b6624272b2924" rel="noreferrer noopener nofollow">[email protected]</a>/Teaching /Users/mystaff/Desktop/DoNotUseTeachingDrive/

关于macos - 通过 AppleScript 安装 SMB 驱动器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19727128/

相关文章:

java - 将 OS X 空间与 SWT 应用程序一起使用

xcode - 代码设计抛出错误 'errSecInternalComponent'

ruby - 无法构建 gem native 扩展(安装 Compass)

bash -/root/.bashrc 是做什么的?

python - Bash while 循环调用 Python 脚本

linux - 'find' 或任何其他工具可以搜索文件广度优先吗?

cocoa - 用于创建将应用程序与 AppleScript 集成所需文件的工具

swift - 在没有 URL 的情况下使用 ZIPFoundation

cocoa - Applescript 不接受 arRsync sdef 命令?

macos - 使用苹果脚本压缩文件夹