【问题标题】:Mac OSX mount smb to /Volumes from scriptMac OSX 将 smb 从脚本挂载到 /Volumes
【发布时间】:2021-01-21 17:22:12
【问题描述】:

我可以使用以下命令将 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 的情况下执行相同的操作?

谢谢

【问题讨论】:

    标签: macos applescript root mount smb


    【解决方案1】:

    回答我自己的问题:

    最初我使用的 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 中安装了网络共享,所以我可以使用它并忽略错误。

    【讨论】:

      猜你喜欢
      • 2022-08-02
      • 1970-01-01
      • 1970-01-01
      • 2014-11-02
      • 1970-01-01
      • 2011-03-07
      • 2016-08-09
      • 2015-11-06
      • 1970-01-01
      相关资源
      最近更新 更多