首页 > 解决方案 > Mac OSX 将 smb 从脚本挂载到 /Volumes

问题描述

我可以使用以下命令将 smb 共享挂载到 /Volumes

osascript -e "mount volume \"smb://user:pass@hal/share\""

但这仅在我已经登录 Mac 时才有效,否则我会收到“无法建立到 WindowServer 的默认连接”错误。

我可以使用 mount 命令挂载到我的主目录中的一个文件夹,无论我是否登录都可以:

mkdir ~/test
mount -t smbfs //user:pass@hal/share ~/test

但是我不能用 /Volumes 来做到这一点,因为它是由 root 拥有的。osascript 调用如何有权写入 root 拥有的文件夹,我如何在不使用 AppleScript 的情况下做同样的事情?

谢谢

标签: macosapplescriptrootmountsmb

解决方案


回答我自己的问题:

最初我使用的 AppleScript 是:

osascript -e 'tell application "Finder" to mount volume "smb://user:pass@hal/share"'

这会产生不同的错误,并且当用户未登录时安装失败:

29:78: execution error: An error of type -610 has occurred. (-610)

我在撰写此问题时发现了不使用 Finder 的更简单版本:

osascript -e ‘mount volume "smb://user:pass@hal/share”’

正如我所说,当用户尚未登录时,这也会出错:

_RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.

但它确实在 /Volumes 中安装了网络共享,所以我可以使用它而忽略错误。


推荐阅读