macos - 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 的情况下做同样的事情?
谢谢
解决方案
回答我自己的问题:
最初我使用的 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 中安装了网络共享,所以我可以使用它而忽略错误。
推荐阅读
- c++ - 每 20 毫秒定期运行线程失败
- sql - 如何使用 Pgadmin 或 Postgresql 查询查找数据上传日期
- maven - 神器部署问题
- google-apps-script - 谷歌脚本中 array.indexOf() 的正则表达式匹配问题
- reactjs - 如何在反应js功能组件中停止多个API请求
- tensorflow - 相同代码中 TensorFlow 2.3.0 和 1.15.0 中的进度输出之间的差异不明确
- typescript - 如何在现有堆栈 AWS Cloudformation 中创建新实例
- python - 我想打印硬拷贝表格和工作人员,例如
- python - python logger在钩子中两次写入字符串
- http - 如何在 Go 中使用 httptrace 跟踪 http.Client